1

I am attempting to strip out <p> tags around <img> tags that are automatically getting generated in a WYSIWYG field.

The error: preg_replace(): Unknown modifier '&gt;'

{{ story.html|raw|replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU','\1\2\3') }}

Thanks!

1

I'm not sure what's going on with the story.html part, but you'll need to double escape your regex.

Assuming you have an entry already with a story Rich Text field, it'd look like this:

{{ entry.body|raw|replace("/<p>\\s*(<a .*>)?\\s*(<img .* \\/>)\\s*(<\\/a>)?\\s*<\\/p>/iU", "\1\2\3") }}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.