3

I have set up a custom field for a category group. How do I get the value of this field in a loop that goes through entries? Each category in the group could have this field's value set as true or false (light switch). I.e. I need to see what category is related to the current entry and then look up the value of this field - there is some html I want to show only if the value is true.

2

You can access a category's fields exactly like you access an entry's fields.

{{ category.myLightswitch }}

So this should do it for your categories loop:

{% for entry in entries %}
    {% for category in entry.myCategoriesField %}

        {{ category }}

        {% if category.myLightswitch %}
            EXTRA
        {% endif %}

    {% endfor %}
{% endfor %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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