1

I've looked around a good bit to see if I could solve this problem on my own. I've managed to get close I believe, but I think I don't quite understand Craft's relationships.

Basically, I have a related projects section on my site. I'm allowing the user to select the related projects with an Entries tag within my matrix. I would then like to compare their selected Entries with projects already added to a Structure - then output attributes that exist only in the Structure.

This is as far as I've gotten:

My Structure Content

{% for entry in craft.entries.section('homePageBanners').limit(3) %}
    {% for block in entry.banner.limit(3) %}

        {{ block.client }}
        {{ block.bannerImage }}

    {% endfor %}
{% endfor %}

My Matrix Entries Block:

{% for entry in block.projectsEntry %}
    <a href="{{ entry.getUrl() }}">{{ entry.title }}</a>
{% endfor %}

I'm not sure how to compare them & pull content based on what the user selects. I looked into relatedTo(), but didn't have much luck with that.

If that's not clear, I can try to be more specific -- please go easy on me, I'm pretty new to Craft.

EDIT:

Maybe this will help clarify {% for entry in block.projectsEntry %}

 {% for project in craft.entries.section('homePageBanners').limit(3) %}
  {% set relatedProjects = craft.entries.section('homePageBanners').relatedTo(project) %}
   {% for project in relatedProjects %}
    <a href="{{ project[0].getUrl() }}">{{ project[0].title }}</a>
   {% endfor %}
  {% endfor %}
 {% endfor %}
  • Still no luck with this unfortunately. – unsider May 18 '15 at 18:33
2

I'm not sure I totally understand your issue, but give this a try in your Matrix code:

{% for entry in block.projectsEntry %}
    <a href="{{ entry[0].getUrl() }}">{{ entry[0].title }}</a>
{% endfor %}

Are you getting any errors in devMode?

  • Thanks for the response. I am not getting any return errors. I edited my original post to help clarify – unsider May 19 '15 at 16:48

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.