1

I have a channel items and a channel colors, and the items channel has a Playa field item_colors that links to the colors channel. What is the best way to loop through the items entries and output a construct like this?

{

  "color_1" : "item_1",
  "color_2" : "item_1",
  "color_3" : "item_1",

  "color_1" : "item_2",
  "color_4" : "item_2",

  "color_5" : "item_3",

  "color_2" : "item_4",
  "color_3" : "item_4",

}

The tricky part is outputting the outer entry title from within the Playa field tag pair. I attempted to do this with a Stash variable:

{exp:channel:entries channel="items" dynamic="no" disable="categories|member_data|pagination"}
  {exp:stash:item_title}{title}{/exp:stash:item_title}
  {item_colors}
    "{title}": "{stash:item_title}",
  {/item_colors}
{/exp:channel:entries}

But the result is the Stash variable outputs the same (last) entry title for every instance. Something about parse order, undoubtedly… any help would be greatly appreciated.

3

Good news, it should be a quick fix. All you need is to prefix your Playa variables with var_prefix parameter to differentiate the namespace from the Channel Entry variables, although you might have to use the full module tag:

{exp:playa:children field="item_colors" var_prefix="pl"}
    "{pl:title}": "{title}",
{/exp:playa:children}
| improve this answer | |
  • Thank you, that is exactly what I needed. Now I don't have to also agonize over why I was apparently able to output the stash variable only once... EE really drives me nuts sometimes! – Charlie Gorichanaz Jan 14 '14 at 23:30

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.