<p>Would using <code>{{ category.id }}</code> work?</p>

CC BY-SA 3.0
2017-02-06T23:24:49.787Z
That works.  I made the mistake of trying {{ category.fieldId }}.
Hellyar
CC BY-SA 3.0
2017-02-06T09:48:12.373Z
2017-02-06T09:48:12.373Z
darylknight
<p><strong>How do I print the field ID of a category field in place of its title?</strong></p>

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

<p><strong>I want to print the field ID of <code>category.title</code> instead.</strong>  </p>

<p>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.</p>

<templating>
How do I print the field ID of a category field in place of its title?
# How do I print the field ID of a category field in place of its title?

(Asked by: username_0 on 2017-02-03)

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.

**Tags:** templating

---

## 1 answers

### Answer by username_1 on 2017-02-06. Score: 2 | Accepted answer

Would using `{{ category.id }}` work?

> **Comments:**
> **username_0**: That works.  I made the mistake of trying {{ category.fieldId }}.  

---

