2

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?

4

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 %}

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.