0

I have two sections: games publishers

For example, a games entry title would be "Mario Brothers" and a publishers entry title would be "Nintendo"

On the entry page for Nintendo, I want to display all games (entries) they published.

The "_entry,html" page for publishers right now only has the following code:

{% extends "_layout" %}

{% block content %}
    <article>
        <h1>{{ entry.title }}</h1>      
        {{ entry.body }}
    </article>
{% endblock %}

So I know I need to add it after:

</article>

In the games section, I have a field called "GamePublishers" set to type Entries. So I assign the publisher of a game via the admin cp. Wasn't sure if I need to also setup a field type entries in GamePublishers to reference to Games section. (If that makes sense)

Thanks

1

Wasn't sure if I need to also setup a field type entries in GamePublishers to reference to Games section.

Not necessary if you already have a "GamePublishers" Entry field in the "Games" section.

Something like this should work:

{% set games = craft.entries.section('games').relatedTo(publisher) %}

That's assuming you've already got a variable named publisher defined that's referencing the current publisher the user is viewing.

I'd suggest reading through the relations docs as well. Craft has a pretty powerful relations engine you can do all sorts of crazy stuff with.

|improve this answer|||||
  • I tried this but didn't work... {% extends "_layout" %} {% block content %} <article> <h1>{{ entry.title }}</h1> {{ entry.body }} </article> {% set games = craft.entries.section('games').relatedTo(publisher) %} <ul> {% for entry in entries %} <li> <a href="{{ entry.url }}">{{ entry.title }}</a> ({{ entry.GamesReleaseYear.format('Y') }}) </li> {% endfor %} </ul> {% endblock %} – DevServe Dec 18 '16 at 23:36
  • That's a bit hard to read, are you defining the variable publisher somewhere? It should be a reference to the publisher the user is currently viewing. – Brad Bell Dec 19 '16 at 0:30
  • Ok, I updated it. It is listing games, but it is listing ALL games and not those specific to the publisher. I'm using: {% set entries = craft.entries.section('games').relatedTo(GamesPublisher) %} – DevServe Dec 19 '16 at 2:11
0

Think I finally got it. Here is my code.

{% extends "_layout" %}

{% block content %}
    <article>
        <h1>{{ entry.title }}</h1>      
        {{ entry.body }}
    </article>

    <h2>Games</h2>

    {% set entries = craft.entries.section('games').relatedTo(entry) %}

    <ul>
        {% for entry in entries.order('title') %}
            <li><a href="{{ entry.url }}">{{ entry.title }}</a>{% if entry.GamesGenre is not empty %} ({% for category in entry.GamesGenre %}{{ category.title }}{% endfor %}){% endif %}</li>
        {% endfor %}
    </ul>

{% endblock %}
|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.