2

We have a single channel that holds all the information for one dataset, in our case, Producers.

We have multiple Event type channels, for each of the Events that our client holds every year.

We then add an entry which holds a relationship field to the Producer channel, so that we can show a list of Producers attending that particular Event.

This works fine, but can be labour intensive if for example 200 Producers attend an Event, as we would have to create 200 new entries in that particular Event type channel.

We thought Playa might make this a better admin process, as it allows you to multiple select relationships within one Playa field. Therefore, each Event type channel would have just one entry, that had a Playa field holding all the Producer relationships.

Trouble is, we can't get this to work with Structure, as Structure does not seem to recognise the individual relationships. The following code lists the Producers for an Event, but does not link through to the detail page as the {page_uri} variable for each listing is empty (this is why we presume the relationship is not recognised):

{exp:structure:entries}

    {exp:playa:children field="producers" limit="5"}
        <p><a href="{page_uri}">{page_uri}</a></p>

    {/exp:playa:children}

{/exp:structure:entries}

Can Expression Engine, Structure and Playa work in this way, and if so, how do we correct the above template code?

2 Answers 2

1

They can work happily together but it looks like you're confusing the benefits of Structure. Structure aims to provide the clients with more of a traditional page-based CMS structure presenting more of a one-to-one relationship with pages to URL's. In your case it sounds like you're working with 'Listings' which are just Channel Entries so you don't really need to use Structure in your templates at all.

Secondly {exp:structure:entries} is not native to Structure. It looks like you're using the Structure Entries addon. Again, this isn't necessary from what you've described.

All you need to do use is the {exp:channel:entries} tag with a {playa} tags inside to output the relationships. So call out the entry based on the entry_id and then output the Playa field of all the Producers who are attending the event. Something like:

{exp:channel:entries channel="events" dynamic="no"}

    {exp:playa:children field="producers" limit="5"}
        <p><a href="{page_uri}">{page_uri}</a></p>

    {/exp:playa:children}

{/exp:channel:entries}

Don't forget that if you're dealing with a Structure managed Listing then you'll need to add dynamic="no" to the Channel Entries tag.

7
  • Aplogies, we've tried using the channel entries tag but with no joy.
    – seavers
    Apr 9, 2013 at 16:35
  • Can you confirm you've included dynamic="no" to the tag? Are you managing your entries from a Structure Listing or as regular Channel Entries? Remember that Structure may or may not be used to manage a Channel. You can confirm this in Structure Settings.
    – Ian Young
    Apr 9, 2013 at 16:56
  • Thanks Ian. Yes, I've included the dynamic relationship ="no" tag. We've almost got it working, see here realfood.symphony-os.co.uk/market/images-from-the-market . The Playa Exhibitor List link (under Images From The Festival) and the Playa 2 List links go to 2 different events pulling through info from the Producer channel. Only problem now is that the detail page for Playa 2 List point to the same detail page as the Playa Exhibitor List (see the breadcrumb and url). This is the reason we are using relationships in the first place, so we can multiple instances of the Producer list.
    – seavers
    Apr 9, 2013 at 17:11
  • OK, glad you're making progress. Are you still using the exp:structure:entries addon? For the detail page it sounds like you'd just need to do a conditional check for the URL segment to redirect appropirately. i.e. {if segment2 =='playa-2-list'}...{/if}
    – Ian Young
    Apr 9, 2013 at 17:58
  • Im using the: {exp:channel:entries channel="playa_2_list" dynamic="no"} {exp:playa:children field="playa_producer_relationship" limit="5"} <p><a href="{page_uri}">{page_uri}</a></p> {/exp:playa:children} {/exp:channel:entries}. Palease could you explain how we'd redirect, I don't know how to influence the URL.
    – seavers
    Apr 9, 2013 at 18:07
0

For the votes up, the answer is not out of the box. Structure can only show a listing once. Use it on another Structure page and the detail page will go to the first page on which you used the listing.

That said, you can use Structure to serve a content page, select a template that shows the content on that page, and then also pulls in results from another channel. This approach only works by using Freebie to break your urls at a predetermined point. The listing view and the detail view are conditionally served in the template I mentioned, you test the URL using Freebie, if it has a segment after the specified break, you server a detail, if its empty, it's a listing.

Here's an example:

  1. Set the Freebie break segments as 'producers' - freebie will look for this in urls, and will give you the functionality as specified on https://github.com/averyvery/Freebie.

  2. Assign a Playa relationship field to the channel that serves the page one level higher than your producers listing page. In this example this is 'Festival One'. The playa field is called 'producers_at_festival'. This makes sense, as we are going to associate our producers that are appearing at Festival One here, in the landing page entry for that festival. We'll pull these relationships later, using the URL segment for this page.

  3. Create a new Structure page called Producers (on the page tree list in Structure), and select the following template as the Structure Template (found in the Structure tab):

    {if segment_3 != "" AND freebie_break_1==""}

    {exp:channel:entries channel="content_page"}

    {title}

    {content}

    {/exp:channel:entries}

    {exp:channel:entries channel="individual_festival_landing_pages" dynamic="no" url_title="{segment_2}"}

    {exp:playa:children field="producers_at_festival" disable="member_data"}

    {title}

    {/exp:playa:children}

    {/exp:channel:entries}

    {/if}

    {if freebie_4 !=""}

    {exp:channel:entries channel="producers" dynamic="no" limit="1" url_title="{freebie_4}"}

    {exp:channel:entries channel="producers"}

    {exp:structure:breadcrumb inc_home="no" inc_separator="no" inc_here="no" add_last_class="no"}

    {if freebie_break_1}

    Producers

    {title}

    {/if}

    {title}

    {/exp:channel:entries}

    {/if}

There's a few things to note, the above only works when the page is called Producers, you'll have to change that to whatever you need. Also, this is the third level down in the navigation, thats why we are checking {freebie_3} for the listing, and {freebie_4} for the detail, so my URL looks like:

Domain.com/festivals/festival-one/producers.

Also note that to show the detail page, we simply call the channel entry by using it's URL, this is the fourth URL segment , after 'producers'. We also use the second segment before 'producers' to pull our relationships.

Our page is in effect made up of:

Structure content page The page one level higher in the URL (that holds the producer relationships) The producer entry.

You can probably make this a bit more dynamic but hopefully it gives a good place to start in terms of logic.

IMPORTANT - there's code being stripped out above, here's an image of the Detail section of the code - Stackexchange - must do better :p

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.