2

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.

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

1 Answer 1

1

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>
1
  • 2
    Really weird... not sure why that would be the case.
    – Brad Bell
    Commented Sep 5, 2014 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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