0

I've got this code snippet I'm working with and I can't get tags pulled out for related entry in current locale.

Maybe worth to mention, that tags is matrix field.

  {% set entries = craft.entries %}

  {% for entry in entries %}
  <h3>{{ entry.title }}</h3>
  {% for tag in craft.tags.relatedTo({
          sourceElement: entries,
          sourceLocale: craft.locale
  }) %}
     <li>
     { tag.title }}
     </li>
     {% else %}
     <li>
     No tags found
     </li>
     {% endfor %}
     {% endfor %}
3
  • Why do you define the locale? Isn't this default behaviour?
    – KSPR
    Feb 23, 2015 at 14:30
  • At link under paragraph 'Getting more serious', it says, that 'you can set the 'sourceLocale' if you want to limit the scope to relations created from a particular field.' Feb 23, 2015 at 14:59
  • Domini, could you please try posting your code snippets properly indented / formatted. Thanks!
    – carlcs
    Feb 23, 2015 at 15:09

1 Answer 1

1

As pointed out in the comments to your question, there's no need to specify the locale with your relatedTo parameter.

I already wrote you in response to your other question, Craft always works in one locale only if you don't explicitly make it to do otherwise.

{% for entry in entries %}

    <h3>{{ entry.title }}</h3>

    {% for tag in craft.tags.relatedTo(entry) %}

        {{ loop.first ? '<ul>' }}
        <li>{{ tag.title }}</li>
        {{ loop.last ? '</ul>' }}

    {% else %}

        <p>No tags found</p>

    {% endfor %}

{% endfor %}
4
  • I've used this code before, it worked until I've added first locale. Feb 23, 2015 at 15:34
  • Can't have anything to do with adding a locale. You probably must have changed something else.
    – carlcs
    Feb 23, 2015 at 16:30
  • For sure. I'm on it now and I'm starting to discover, that It might cause the matrix field. I had tags in Assets field before I think. Could that be the problem? Feb 23, 2015 at 16:36
  • I can't follow, Dominic. What matrix and or assets fields are you talking about? Please feel free to add a new question, "Display tag related to entry in current locale" has nothing to do with all this and is answered in my opinion.
    – carlcs
    Feb 23, 2015 at 16:44

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.