0

How do I print the field ID of a category field in place of its title?

{% for entry in craft.entries.section('posts').relatedTo(category) %}
    some html...
    {% for category in entry.market.level(2).find() %}
        {{ category.title }}
    {% endfor %}
{% endfor %}

I want to print the field ID of category.title instead.

Reason = I am using the printed output as a class to filter against. Some of the category titles contain more than one word and I do not want to add a hyphen to each instance. So, using the field ID in place of category.title would solve this problem.

2

Would using {{ category.id }} work?

1
  • That works. I made the mistake of trying {{ category.fieldId }}.
    – Hellyar
    Feb 6 '17 at 23:24

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.