4

I'm having a bit of a stash dilemma brought about by my need to have modal window content inserted at the end of the parent HTML document. Here's the scenario:

I have a "gallery" index template that uses a gallery-pages channel to create the pages within the section. Within that group, I have a radio button field type that the admin uses to select which content (from a pre-existing, pre-formatted list of options) should be inserted after the body field. It is within this radio button that "photo gallery xyz" is selected, which uses an embed to insert a loop coming from the photos channel.

The gallery index template has all this logic in it, with a simple outline like this:

{exp:channel:entries channel="gallery_pages" limit="1"}
{exp:stash:set_list name="page_body"}
    {stash:other_variables}
    {stash:entry_body}
       {page_body}
       {if radio == ""}{/if}
       {if radio == "1"}{embed=gallery1}{/if}
       {if radio == "2"}{embed=gallery2}{/if}
       {page_extended}
    {/stash:entry_body}
{/exp:stash:set_list}
{/exp:channel:entries}

And so each gallery embed would contain a loop from the photos channel (don't mind the conditional above - I'm actually using switchee). But the reality is, I need two of them - a loop for the displayed items in the page, and a loop to generate the modals for each item in the display loop (which get matched up by entry ID). And so I'm wondering how I might be able to achieve this. In a perfect world, I'm imagining a stash:set_list inside the embed, setting the display items as variables and the modals as separate variables, which I could then stash:get_list together in the inside layout template. Something like this:

{exp:channel:entries channel="photos" limit="30"}
    {exp:stash:set_list name="display_photos"}
        {stash:photo1}{photo1:small}{/stash:photo1}
        {stash:photo2}{photo2:small}{/stash:photo2}
        {stash:photo3}{photo3:small}{/stash:photo3}
        {stash:modal1}{photo1:large}{/stash:modal1}
        {stash:modal2}{photo2:large}{/stash:modal2}
        {stash:modal3}{photo3:large}{/stash:modal3}
    {/exp:stash:set_list}
{/exp:channel:entries}

But I can't but stash in an embed that itself is stashed, can I? I tried it and got no variables set from within the embed. But I suspect there must be a way to achieve what I'm looking to do - I just can't seem to piece it together, though it seems similar in principle to this post on nesting channel entries with stash (which is effectively what I'm doing via the embed).

UPDATE: It's hard to describe without posting a lot of the template, but basically, I have a wrapper entries loop with a limit of 1 to create "pages" like company history, management, staff, etc. within the "about" channel, for example. On the "staff" entry, I use a radio button to select the fact that i want a list of staff from the staff channel to appear after the page body - which is presented with an entries loop. So I have nested entries loops. In this one particular case, let's say from the staff list, I want to click on a staff person to open a modal. The modal markup needs to jump to the bottom of the HTML just before for example. So my entries loop of staff really is building two lists - the list of content to display in the page, and a hidden list at the bottom of the HTML markup.

UPDATE 2: Here's what I've done in my template so far:

 {exp:channel:entries set_name="gallery-pages" limit="1" dynamic="no" disable="{gv_disable_all}"}

 {exp:stash:set_list name="entry_body_content" scope="site" parse_tags="yes" parse_conditionals="yes"}

    {stash:entry_title}{title}{/stash:entry_title}

    {stash:entry_body}{cf_{my_main_channel_prefix}_body}{/stash:entry_body}
    {stash:entry_list_after}

        {exp:switchee variable="{cf_{my_main_channel_prefix}_list_after}" parse="inward"}
            {case value="none|"}{/case}
            {case value="photos"}
                {embed="embeds/.gallery_cases_list"}
            {/case}
        {/exp:switchee}

    {/stash:entry_list_after}
    {stash:entry_modals}

        {exp:switchee variable="{cf_{my_main_channel_prefix}_list_after}" parse="inward"}
            {case value="none|"}{/case}
            {case value="photos"}
                {embed="embeds/.gallery_modals_list"}
            {/case}
        {/exp:switchee}

    {/stash:entry_modals}

    {stash:entry_extended}{if cf_{my_main_channel_prefix}_extended}{cf_{my_main_channel_prefix}_extended}{/if}{/stash:entry_extended}

{/exp:stash:set_list}
  {/exp:channel:entries}

I have other stashed elements as well, such as description and title for the area, but this is the "core" for the body.

This allows me in my inside layout template, within the main content area, a simple structure of

  • Body
  • List After content (if applicable)
  • Extended Body (if applicable)

and right before I can then insert the modals, if applicable (they'd only apply in certain cases - basically any time I assemble an image gallery wherein I want to use a modal window to display a larger version of the contents).

Of course the big issue here is performance and efficiency. .gallery_cases_list and .gallery_modals_list contain loops of the same channel entries. But I was stumped on how else to do it. Yes, I did try using a stash embed, but I still found I had to use two of them to generate my separately stashed lists of display items and modal items, so there wasn't much of a gain when I tried it that way.

  • Add the id to two lists? And if you're using switchee and stash, is there still a need to use embeds? – GDmac Jan 15 '13 at 9:36
  • Because I have an entries loop inside an outer entries loop, I thought that an embed - whether a native embed of a stash embed - would still be needed, unless there's another way I'm not thinking of. The challenge is, within the content of the conditionally inserted interior entries loop, I have a need to build two data sets - the displayed fields for each entry, as well as a hidden list of modals for each entry. Stash would ordinarily do that, but I don't think I can use stash:set inside an embed that itself is wrapped with a stash:set. – Jean St-Amand Jan 16 '13 at 12:36
  • Show me what the different gallery embeds look like? How different are they? There may be a way to do this without an embed at all. – adrienne Jan 16 '13 at 22:16
  • 1
    Channel Entries can't be nested but exp:stash:set_list and exp:stash:get_list have no problem, providing you append a 4th tagpart to the nested tagpair and use the prefix parameter. As far as I can tell you need a very similar solution to this one: expressionengine.stackexchange.com/questions/1912/… - but you need to output the same list twice in the markup? Can't you just use stash:get_list twice? I think you need to paste more of your template because I'm struggling to see what the real problem is here. – Mark Croxton Jan 17 '13 at 18:08
  • 2
    Example of nesting lists, from the docs: github.com/croxton/… – Mark Croxton Jan 17 '13 at 18:11
1

From comments above from Mark Croxton:

Channel Entries can't be nested but exp:stash:set_list and exp:stash:get_list have no problem, providing you append a 4th tagpart to the nested tagpair and use the prefix parameter. As far as I can tell you need a very similar solution to this one: Nesting channel entries in Stash - but you need to output the same list twice in the markup? Can't you just use stash:get_list twice? I think you need to paste more of your template because I'm struggling to see what the real problem is here.

Example of nesting lists, from the docs: https://github.com/croxton/Stash#example-usage-5-nesting-yep-you-really-can-do-this

| 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.