1

I'm trying to list some entries from specific channel and get the access to matrix fields. The problem is that some of the entries are listed twice or even often. How do I remove the duplicates?

    {% for coupon in craft.entries.section('coupons').status('live').order('postDate asc') %}
        {% for content in coupon.contentBuilder %}
        {% endfor %}
    {% endfor %}
  • The loop through craft.entries.section('coupons') should not list entries multiple times! – carlcs Oct 22 '15 at 7:25
1

I wasn't able to understand how to apply your suggestions and went with this route:

{% for coupon in craft.entries.section('coupons').limit('30').status('live').order('postDate asc') %}
    {% set image = coupon.contentBuilder.type('image').first() %}
       {# multiple times for each of the required fields #}
       {# here comes some other code related to field's value manipulations #}
{% endfor %}
1

You'll have to build a list of the data and then display it.

{% set arr = [] %}

{% for coupon in craft.entries.section('coupons').status('live').order('postDate asc') %}
    {% for content in coupon.contentBuilder %}
        {% set arr = arr|merge([content.myUniqueFieldName: content]) %}
    {% endfor %}
{% endfor %}

{% for item in arr %}
    {{ item.title }}
{% endfor %}
  • Hey, it shows me this error - A hash key must be followed by a colon (:). Unexpected token "punctuation" of value "." ("punctuation" expected with value ":") Also would you please explain this line - content.myUniqueFieldName: content I'd like to get all the fields from matrix not just a single one. Should I ignore myUniqueFieldName ? – Mark H. Oct 22 '15 at 16:17
  • Sorry, I fixed my code (I quickly bashed it out the other day while at work). I see you solved your problem anyway, well done. – Rick Oct 24 '15 at 8:56

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.