When checking if a field has content or not in my templates I usually write something along the lines of:
{% if entry.fieldHandle|length %}
<h1>{{ entry.fieldHandle }}</h1>
{% endif %}
Writing the same code without the |length
filter does also work, so can I just exclude the use of the filter from my code altogether? Are there any caveats with not using the filter?
As an aside, I am aware that |length
does have its uses. You can use this to check the exact value of something, etc etc.
This question was more suited for a simple yes/no check to see if a field has any content and outputting something if it does.
Another example of the |length
filter in my code would be something like:
{% set homepageServices = craft.entries.section('services').type('serviceGroup').level(1) %}
{% if homepageServices|length %}
<p>Output the services here</p>
{% endif %}
Would removing |length
(which does work at the moment) cause me any headaches down the line?