2

I have a rich text field which contains:

<p><br></p>

This is what is left when you delete all content of a redactor field. This can't be deleted without the HTML view of Redactor.

Is it possible to write a conditional that checks for an empty field ignoring HTML markup?

{% if entry.poorText is not empty %}
   {{ entry.poorText }}
{% endif %}

Does not work in this case.

6

You can use the striptags filter to remove all HTML tags from your string. With the trim filter you can strip all whitespace from the beginning and the end of it:

{% if entry.poorText|striptags|trim %}
    {{ entry.poorText }}
{% else %}
    Here could be a nicely formatted text! 
{% endif %}
| improve this answer | |
  • 1
    in twig, an empty string evaluates to false, so you could just test {% if entry.poorText|striptags|trim %} – Marion Newlevant Dec 18 '14 at 18:06
  • Right. Thx @Marion. – carlcs Dec 18 '14 at 18:12

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.