2

I have a redactor type field in my CMS (I use Craft CMS), where the user can enter some "variables" like so:

"Hello, {name}"

The only problem is that, when HTML purifier is enabled, it strips all such "variables" that are in href attributes and replaces them with a code. For example:

<a href="tel:{client tel}">{client tel}</a>

becomes

<a href="tel:7207">{client tel}</a>

I can of course disable HTML purifier, but I would rather not. I'm just having difficulty in finding the correct purifier config for allowing the desired behavior. Can anybody help with this?

psithu
  • 21
  • 1
  • I cannot confirm this behaviour – Erik Pöhler Jul 08 '21 at 10:35
  • I just tested this in a fresh Craft3 install with Redactor plugin. Although I do not find a Purifier on/off switch anywhere, the HTML output is as expected. And I did try with and without purify filter. ``` {% for entry in entries %}
  • {{ entry.getLink() }} – {{ entry.test|purify }}
  • {% endfor %} ``` Output is: ```

    Hello, {name}

    ``` What are you trying to do here? Pre-rendering Email templates? Whats the non-Twig placeholder for? – Erik Pöhler Jul 08 '21 at 10:41
  • The usual way to do this is (1) save the un-purified HTML if you need it across sessions (not sure if you do, I don't know what your use-case is, exactly), (2) purify it on output whenever you need to display it in a preview; then when you want to render it with values (3) do variable substitution *first*, (4) run HTML Purifier on the result. You'll actually want to run HTML Purifier on the result anyway, because "name" could be "``". I'm not familiar with Craft CMS and whether it lets you tweak the order, unfortunately. – pinkgothic Jul 09 '21 at 08:19