Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

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?

share|improve this question
    
Why not check for the field's existence in an entry? –  Bryan Redeagle Jun 26 at 16:00
add comment

1 Answer 1

up vote 7 down vote accepted

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.

share|improve this answer
1  
Thank you Patrick. –  user1070143 Jun 26 at 16:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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