Remove or clean HTML tags from a Template Variable field for inserting into an RSS feed?

When using something like getResrouces or pdoResources, is there a way to strip out certain rich text HTML tags from a template variable field before it gets inserted into an RSS feed?

Depending on your needs, you could use an Output Filter if you find a fitting one. Additionally, there’s always the option to write your own Custom Output Filter to apply a regular expression for example.

1 Like

I’m not sure what you’re trying to accomplish, but I also do have outputs where I need to restrict to only HTML “inline-elements”. I have a snippet, that I use as output-modifier. The snippet in my case is called OnlyInlineElements:

<?php
$allowedElements = '<a><abbr><acronym><b><bdo><big><br><button><cite><code><dfn><em><i><img><input><kbd><label><map><object><q><samp><select><small><span><strong><sub><sup><textarea><time><tt><var>';

return strip_tags($input, $allowedElements);

And I use it like this:

<span aria-label="[[%website.label.openinghours]]">
  [[++contact_hours:stripString=`  `:OnlyInlineElements]]
</span>

Can you explain what that is doing? I’m assuming that ++contact_hours is a variable from the Configuration plugin and :OnlyInlineElements is running the snippet.

But, what is stripString= doing?

I’m 99% sure, your assumptions are correct.

stripString is a regular output filter and in this case strips double spaces by the looks of it. Basically it strips anything you define in the followed quotes.

I think the built in MODx output modifier striptags is going to work.

100% correct.

The ++contact_hours is a field in my ClientConfig:

image

And this part: :stripString= :OnlyInlineElements are two chained Output Modifiers.

From the documentation:

Because I noticed on more than one project, that people often try to use multiple spaces to “position” text different, I counter-acted with stripping away every “double space”, by using
:stripString=` `

stripString is one of the many built-in Output-Modifiers by MODX:

stripString	// Strips string of specified value	// [[+name:stripString=`Mr.`]]

And my OnlyInlineElements is a snippet, which in this case I use as custom Output Modifier, because in the default footer of my framework, I need the “opening hours / contact hours” inside a table-cell, so no block-elements are allowed there (or in the example above inside a span on another location, and spans also don’t allow block-elements inside).

1 Like