Wondering how to write a conditional that was dependent on the length of a plain text field within a matrix field. I have something like:

{% for block in entry.pricing %}
    <li>{% if block.destination|length > 25 %}TEST{% endif %}{{ block.smallCost }}</li>
{% endfor %}

Where I’m trying to add TEST if the length of the string of block.destination is more than 25.

  • That should work as far as I can tell. What happends if you try to output {{ block.destination | length }}? – André Elvan Sep 5 '14 at 12:33
  • It outputs totally fine, giving the length of the string. It’s just the conditional I can’t figure out? – simonsweeney Sep 5 '14 at 16:44

Turns out it needs the space in the conditional either side of the vertical bar so the code should’ve been:

<li>{% if block.destination | length > 25 %}<br />{% endif %} {{ block.smallCost }}</li>
| improve this answer | |
  • 2
    Really weird... not sure why that would be the case. – Brad Bell Sep 5 '14 at 17:27

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.