1

I'm displaying a list of Packages and within those Packages are Products. The Packages channel entry has a Playa field populated by Product channel entries. So to display them I have something like this:

{packages} {!-- Playa field --}

{exp:playa:children field="packages_products"} {!-- Playa entries --}
{product 1}
{product 2}
{/exp:playa:children}

{/packages)

I have detailed descriptions for the Products that are hidden until clicked on and they expand, using Bootstrap's Collapse plugin. And the issue I'm running into is that I need each Product to have some sort of unique identifier because each Package can have one or more of the same Products.

So looking at the example below you can see that Product 2 is in both Packages. Using Bootstrap's Collapse if you click on Product 2 in Package 1 the details will expand, BUT clicking on Product 2 in Package 2 only expands Product 2 in Package 1. Essentially I need to add some sort of unique identifier to every Product that's repeated across Packages in order for Collapse to work correctly.

{packages} {!-- Package 1 --}
{exp:playa:children field="packages_products"} {!-- Playa entries for Package 1 --}
{product 1}
{product 2}
{/exp:playa:children}
{/packages)

{packages} {!-- Package 2 --}
{exp:playa:children field="packages_products"} {!-- Playa entries for Package 2 --}
{product 5}
{product 2}
{/exp:playa:children}
{/package)

Theoretically I'd be able to grab the entry_id of the Package channel entry that the Product Playa entry is in, so something like this:

{packages} {!-- Package 1 --}
{exp:playa:children field="packages_products"} {!-- Playa entries for Package 1 --}
{product 1}
{product 2-1}
{/exp:playa:children}
{/packages)

{packages} {!-- Package 2 --}
{exp:playa:children field="packages_products"} {!-- Playa entries for Package 2 --}
{product 5}
{product 2-2}
{/exp:playa:children}
{/package)

But I've tried for the last few hours and haven't figured it out. Any thoughts?

UPDATED More specific code from my template:

{films_packages_products}
{exp:playa:children field="packages_products"}
<h3>{packages_name}</h3>
<ul>
<li>
{products_summary}
{!-- need a unique id for the Collapse js to target next line --}
<a data-toggle="collapse" data-target="#{unique id}_{url_title}">More Info</a>
{!-- need a unique id for the Collapse js to target next line that matches the above --}
<div id="{unique id}_{url_title}" class="collapse">
{products_features}
<li>{feature_bullet}</li>
{/products_features}                                            
</li>
</ul>
{/exp:playa:children}
{/films_packages_products}
5
  • Can you post more of the template code with your html?
    – Siebird
    Commented Apr 26, 2013 at 0:46
  • Are you making each package an accordion group? It's the accordion group that receives the unique identifier (which could be the entry ID for the package entry), and then the child elements refer to the accordion group ID with the data-parent param for the open/close toggle, which SHOULD open only child elements of the parent accordion group. Is that not how it's behaving when there's more than one accordion? Commented Apr 26, 2013 at 0:59
  • @JeanSt-Amand The Packages aren't an accordion group, the Products are in order to display more info on them when clicked. Commented Apr 26, 2013 at 5:53
  • @Siebird just added template code. Commented Apr 26, 2013 at 6:05
  • Looks to me based on your template code that the packages are the accordion group - in other words, each package is a parent with child products, and each product expands and collapses. They're not one giant accordion, right? There would be one per package with the products within that package being what shows/hides on click of the product's more info link? Commented Apr 26, 2013 at 11:02

1 Answer 1

1

If your {exp:playa:children} tag pair is within an {exp:channel:entries} tag pair, you can use the var_prefix parameter on the {exp:playa:children} to tell Playa to only parse certain variables with that prefix:

[removed code - updated answer]

Update

Sounds like your nesting playa fields, so use two {exp:playa:children} tags with var_prefix's so playa knows which fields to parse for each channel.

{exp:playa:children channel="films" field="films_packages_products" var_prefix="films"}
    {exp:playa:children channel="packages" field="packages_products" var_prefix="packages"}
    <h3>{packages:title}</h3>
        <ul>
            <li>
            {packages:products_summary}
            {!-- need a unique id for the Collapse js to target next line --}
            <a data-toggle="collapse" data-target="#row_{films:entry_id}-{packages:entry_id}">More Info</a>
            {!-- need a unique id for the Collapse js to target next line that matches the above --}
            <div id="row_{films:entry_id}-{packages:entry_id}" class="collapse">
                <ul>
                {packages:products_features}
                <li>{packages:feature_bullet}</li>
                {/packages:products_features}
                </ul>                                           
            </div>
        </ul>
    {/exp:playa:children}
{/exp:playa:children}
4
  • So {exp:playa:children} is nested in {films_packages_products} which is a Playa field that's nested in a {exp:channel:entries} tag pair. I gave it a try, but {packages:entry_id} is not parsing, it just returns {packages:entry_id}. Commented Apr 26, 2013 at 16:43
  • Is {films_packages_products} & {packages_products} different playa fields? If not, then just remove the opening & closing {films_packages_products} tag and add a parameter to the playa module tag: {exp:playa:children field="packages_products" entry_id="{entry_id}" var_prefix="packages"}
    – Siebird
    Commented Apr 27, 2013 at 1:30
  • So {film_packages_products} is a Playa field inside a "Films" Channel entry that pulls from a "Packages" Channel. The "Packages" Channel has the Playa field {packages_products} that pulls from a "Products" Channel. Does that make sense? And thanks for the help so far! Commented Apr 28, 2013 at 17:44
  • Just updated my answer for nesting playa fields.
    – Siebird
    Commented Apr 29, 2013 at 12:35

Your Answer

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

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