2

I am currently trying to loop through channel "promos", where each entry has a Playa field designating which entries that particular promo should display on:

{exp:channel:entries channel="promos" orderby="promos_order"}
    {exp:playa:children field="promos_show_on_page" child_id="{current_entry_id}" var_prefix="playa"}
        <a href='{promos_link}'><img src="{promos_image}" /></a>
    {/exp:playa:children}
{/exp:channel:entries}

My issue is that I don't know how to pass in the current_entry_id to the child_id parameter.

Is this possible with or without any particular plugins or extensions, or am I going about this in the completely wrong way?

2

You want to use playa:parents, not channel:entries. Playa will infer the entry_id so long as you place this tag loop within the channel:entries tag of the entry you're viewing. (You can pass it via the entry_id parameter if you like.)

{exp:playa:parents channel="promos" field="promos_show_on_page" orderby="promos_order"}
    <a href='{promos_link}'><img src="{promos_image}" /></a>
{/exp:playa:parents}
3
  • 1
    I though it was that the playa field was contained in the promos channel field group. Seems not. Good catch, Derek. Sep 5 '13 at 18:24
  • 1
    Actually, that is the case. But he wants to find which promos (parents) to show based on the entry he's viewing (child). These relationships can be confusing! Sep 5 '13 at 18:31
  • 1
    Yessir. Brutal. Sep 5 '13 at 19:06
0

It doesn't seem to me like you would need the child_id param if you're looking for the playa loop to display the children of each entry in your promos entries loop of the "promos" channel. It would do that automatically, with each loop being within each returned entry of the entries loop. Without that parameter, the children loop would assume the parent to be the current entry.

3
  • But the child_id parameter is what's matching the current entry. The parent is the promos entry.
    – jrrdnx
    Sep 5 '13 at 15:43
  • 1
    You're already mapping it to the current entry by (a) nesting it within the entries loop and (b) by specifying within which field of the entries loop the children may be found. If the children loop was OUTSIDE the entries loop, it would be a different story. Sep 5 '13 at 16:10
  • Maybe I'm confused or not using the correct terminology (I'm somewhat new to EE), but the children of the promos_show_on_page field references the pages that each promo should be displayed on. So I'm trying to verify that the current page the user is on is included in those children, and displaying that promo if so.
    – jrrdnx
    Sep 5 '13 at 16:48
0

I may be missing something here, but you should just be able to use the {entry_id} tag as mentioned in the playa docs here.

entry_id

The parent entry’s ID(s). If your tag is within an {exp:channel:entries} tag pair, this will default to the current entry’s ID.

So you would have something like this:

{exp:channel:entries channel="promos" orderby="promos_order"}
    {exp:playa:children field="promos_show_on_page" child_id="{entry_id}" var_prefix="playa"}
        <a href='{promos_link}'><img src="{promos_image}" /></a>
    {/exp:playa:children}
{/exp:channel:entries}

UPDATE Using the example I described below, you would use embed variables. Once you pass the variable and value to the embed template, you can use it instead like this:

{exp:channel:entries channel="promos" orderby="promos_order"}
    {exp:playa:children field="promos_show_on_page" child_id="{embed:main_entry_id}" var_prefix="playa"}
        <a href='{promos_link}'><img src="{promos_image}" /></a>
    {/exp:playa:children}
{/exp:channel:entries}   
4
  • But that entry_id is tied to the current channel entries loop, correct? I need it to reference the entry id of the actual page being viewed.
    – jrrdnx
    Sep 5 '13 at 16:44
  • Yes, it would be the current entry in the loop. I guess I missed that you were in a multi-entry template. Sorry. So the playa field is NOT related to the entries in the channel loop?? If your playa field is in the entries under the channel "promos", that is what you would be retrieving anyway. I guess I don't understand. What entries/channel are the playa field related to and what entries/channel are you "viewing"? Is this code snippet in an embed from another template in which the playa field is related?
    – W3bGuy
    Sep 5 '13 at 17:09
  • This code resides inside an embedded template and will display the promos in the sidebar on pages from multiple channels (pages, testimonials, etc.). The Playa field exists in the Promos channel and displays a list of all pages (again, from multiple channels) on which each particular promo should be displayed.
    – jrrdnx
    Sep 5 '13 at 17:29
  • If this is the case, pass the entry_id to the embed template. like this: {embed="template_group/embed_template" main_entry_id="{entry_id}"} Then in your embed template, use the embed value to check. I'll update my answer above to show you the difference.
    – W3bGuy
    Sep 5 '13 at 17:31

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.