1

I’m using the LJ Dynamic Fields plugin and have a dynamic multi select setup for the client to select predefined tags, which is working all fine in the cms using the following code.

{% for tags in craft.tags.group('default').limit(null).order('title') %}
{ "value":"{{ tags.id }}" , "label":"{{ tags | raw | capitalize }}"
}{% if not loop.last %},{% endif %}
{% endfor %}

However, in my template I can only seem to output the id, but I want the tag title. I’m using the following code in my template:

{% for tags in entry.tagsMultiSelect %}
<a href="">{{ tags }}</a>
{% if not loop.last %}, {% endif %}
{% endfor %}

Can anyone tell me where I’m going wrong?

3

The values in your tagsMultiSelect are the tag ids, not the tags. So, what you need to do in your template is convert that id to a tag:

{% for tagId in entry.tagsMultiSelect %}
  {# get the tag with that id #}
  {% set tag = craft.tags.id(tagId).first %}

  <a href="">{{ tag.title ?? 'no such tag' }}</a>
  {% if not loop.last %}, {% endif %}
{% endfor %}

If what you want is a predefined set of tags, you might also consider changing that tag group into a category - that would let you use a regular category field for your tagsMultiSelect.

| improve this answer | |

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.