{% if entry.fieldHandle %}
{{ entry.fieldHandle}}
{% else %}
{{ global.fieldHandle}}
{% endif %}
Doesn't seem to be rendering for me. The entry field shows up when it's true, but the global field doesn't in the cases it needs to.
{% if entry.fieldHandle %}
{{ entry.fieldHandle}}
{% else %}
{{ global.fieldHandle}}
{% endif %}
Doesn't seem to be rendering for me. The entry field shows up when it's true, but the global field doesn't in the cases it needs to.
The reason it wasn't rendering is because my original entry field is an Entries Field (see templating examples in the docs). The relationship fieldtypes (Entries, Assets, Users) require that you include the length filter in your conditional like so:
{% if entry.fieldHandle |length %}
{{ entry.fieldHandle}}
{% else %}
{{ global.fieldHandle}}
{% endif %}
Thanks to Keith Mancuso @keithmancuso for the fix!
length in your conditional. Hope you didn't mind?! :)
– carlcs
Jul 09 '14 at 22:52
{{ entry.fieldHandle|length ? entry.fieldHandle : global.fieldHandle }} ... Same code written as a simple ternary operator.
– Lindsey D
Jul 10 '14 at 04:55
For a relationship field you should use the length filter:
{% if entry.fieldHandle|length %}
Or the more efficient total function to get and check against the total number of elements that match the criteria:
{% if entry.fieldHandle.total %}
A more detailed answer on how to test for empty fieldtypes is here: https://craftcms.stackexchange.com/a/842/9
Note: this answer was edited based on clarification of the question as well as the comments below
{% if entry.fieldHandle %} and {% if entry.fieldHandle is not empty %} would be pretty stellar. I'd post it, but then I'd feel vaguely guilty since you Bens brought it up.
– Matt Stein
Jul 09 '14 at 16:46
{% if entry.fieldHandle %} is Craft specific and depends on the type of field. See Brandon's comment on g+.
– carlcs
Jul 09 '14 at 22:28