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 have one tag for each entry.

 - Entry1
     Tag1
 - Entry2
     Tag2

Now I want to show them in the title of each entry. But it doesn't work.

{% for entry in craft.entries.section('mainEntry').limit(4) %}
{% set tag = entry.mainEntryTag.first() %}
  <h2>{{ tag }} {{ entry.title }}</h2>
{% endfor %}

This results in displaying only the globally first tag:

- Entry1
     Tag1
- Entry2
     Tag1

If I just write: {% set tag = entry.projektart %} I get the error: Object of class Craft\ElementCriteriaModel could not be converted to string

How can I get to current entry tag?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

You're very close. Change "set tag" to "set tags" so you have:

{% set tags = entry.projektart %}

And then loop through the tags:

{% for tag in tags %}
    {{ tag }}
{% else %}
    No tags found
{% endfor %}

You could also simplify this and instead of setting the "tags" variable you could write the following:

{% for tag in entry.projektart %}
share|improve this answer

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.