I've got a generic template that can display entries from different channels. How in the template can I test if a field has been has been assigned to any given channel?
Asked
Active
Viewed 132 times
4
-
Why not check for the field's existence in an entry? – Bryan Redeagle Jun 26 '14 at 16:00
1 Answers
8
Twig has a "is defined" test that you can apply to a variable to see if it exists:
{% if entry.possibleField is defined %}
Yup!
{% else %}
Nope!
{% endif %}
And here is more information on using is defined.
nicael
- 2,382
- 7
- 27
- 48
Patrick Harrington
- 1,080
- 6
- 9