< > greater/less than is converted to html entity in WYWYWIG field type
Created 5 years ago by radja

Hello everybody, First of all I've been using Pyro 2 for a while am just now switching to v3. So I'm having to learn a lot of new things and am still quite lost... I have run across a problem using when editing the content of a page using the "greater than" and "less than" characters, < & >, as they are converted to their HTML entity equivalent '>' and '<'. To demonstrate the problem here is a snippet:

{% set x = 1 %} {% if x > 1 %} {{x}} {% else %} Not bigger! {% endif %}

This code should work and yet on my site it gets broken by the HTML conversion. So what am I missing?

finnito  —  5 years ago

Hey @radja! I also moved from Pyro 2 and it can be confusing at the start!

When rendering a WYSIWYG field (https://pyrocms.com/documentation/wysiwyg-field-type/2.2/usage/presenter-output) it’s worth checking that you have |raw on the end of the Twig tag otherwise HTML entities don’t come through properly in the frontend of your website.

If that’s not it, could you give some more details about how you are rendering your field and how you are populating it in the backend?

radja  —  5 years ago

Thanks for taking the time to answer @finnito !

I finally did things a bit differently, but still... I don't see how I could use raw on this part of the syntax {% if x > 1 %}, since that becomes {% if x &gt; 1 %} and that is the problem!

One solution is to move that code to the page layout model, and there, the < > operators are not transformed. But that is not a very flexible approach.

It was possible with PyroCMS2 and LEX, and logically it should work here as well, i guess it's the WYSIWYG field type that is transforming (for security reasons probably) the '>' into &gt; So I'm wondering if there is some way to tweak how the field type is sanitizing the input?...