1
  • I have a Matrix with an entry field.
  • I have a Loop which is looping entries out of a section.

Goal: The entries from the matrix should not appear in the loop of the section. So the Matrix defines Starred Member Profiles and the loop trough the section is a teamlist, but the two starred profiles should not appear in there.

I tried something like this but i stuck right now...

{# Get the profiles which are in the matrix #}
{% set highlightProfiles = entry.highlightProfiles.all() %}

{% for profile in highlightProfiles %}

 {# Just a test to see the ID of each single entry #}
 {{ profile.hightlightProfileTeaser.one().id() }} 

 {% set highlightProfileSingleIds = profile.hightlightProfileTeaser.all().ids() %}

{% endfor %}

{# set something up for the entry ids which should not join in the endloop #}
{% set highlightProfileIdsString = highlightProfileSingleIds | join(', not ') %}

{% set teamMembers = craft.entries({
 section: 'profiles',
 limit: 50 
}) %}

{% set allProfilesWithOutHighlights = teamMembers.id('and, not '~highlightProfileIdsString).orderBy('title asc') %}
{% for member in allOtherMembers.orderBy('title asc').all()  %}
 {{ member.title }} {{ member.id() }} {{ loop.index }}
{% endfor %}
3

You are on the right track, to “collect” the entry IDs you have to use the merge filter in your Matrix loop though.

{% set highlightProfileSingleIds = [] %}

{% for profile in highlightProfiles %}
    {% set ids = profile.hightlightProfileTeaser.ids() %}
    {% set highlightProfileSingleIds = highlightProfileSingleIds|merge(ids) %}
{% endfor %}
1
  • works! thank yoou! Jul 8 '18 at 12:51

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.