Output Modifiers

Output Modifier to Strip MODX Tags

hearty fare

Strip MODX Tags

Sometimes you want to use content that contains a snippet or other MODX tag for a description or summary, but you don't want the MODX tag to be repeated. MODX 2.5 comes with an output modifier to strip MODX tags.

josh asked...

formit2db is adding two records every time I submit - anyone seen that before?

The Solution:

josh says...

FormIt was executed twice because content was called twice (in description tag too). I have to remove the modx tags there and have written a regular expression for that. Then Jako created a PR for the revolution github repo with that.

<meta name="description" content="[[*description:default=`[[*content:stripmodxtags:striptags:htmlspecialchars]]`]]">

What's the Story?

MODX 2.5 now comes with an output modifier to strip MODX tags. For MODX versions prior to that, you need to create a custom modifier snippet named stripmodxtags.

return preg_replace("/\\[\\[([^\\[\\]]++|(?R))*?\\]\\]/s", '', $input);

Then you need add another custom modifier snippet, htmlspecialchars, to fix quotes:

return htmlspecialchars($output,ENT_QUOTES, $modx->getOption('modx_charset',null,'UTF-8'));