0

Stash 2.6.7 EE 2.10.1

I've been stumped on this one for over 8 hours and feel like I'm overlooking something so simple. I've reviewed the Low parse order guide but still can't get it to work. I've tried different routes with using get_list, setting exp:stash:set to snippet type, etc.

{!-- LIMIT & GRAB ONLY FIRST CATEGORY NAME OF ENTRY (Entry can have multiple categories) --}
{exp:channel:entries channel="resources" dynamic="no" limit="6" disable="member_data|pagination"}
    {exp:stash:set name="entry_{entry_id}_category" trim="yes" parse_tags="yes" parse_depth="2"}
            {exp:gwcode_categories entry_id="{entry_id}" depth="1" limit="1" style="linear"}
                {cat_url_title}
            {/exp:gwcode_categories}
    {/exp:stash:set}
{/exp:channel:entries}

{!-- DROP IN STASH VARIABLE FOR FLEXIBLE TAG PAIR --}
{exp:stash:parse process="end"}
{exp:channel:entries channel="resources" dynamic="no" limit="6" disable="member_data|pagination" parse="inward"}

            {{stash:entry_{entry_id}_category}_resource_images}
            <div class="thumb">
                <a href="#"><img src="{image:url:small}" alt=""></a>
            </div>
            {/{stash:entry_{entry_id}_category}_resource_images}

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


--------


{!-- WORKS IF I SIMPLY DROP IN SEGMENT_2 (which is "print" category) --}
{exp:stash:parse process="end"}
{exp:channel:entries channel="resources" dynamic="no" limit="6" disable="member_data|pagination" parse="inward"}

            {{segment_2}_resource_images}
            <div class="thumb">
                <a href="#"><img src="{image:url:small}" alt=""></a>
            </div>
            {/{segment_2}_resource_images}

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

As you see in the third block above, replacing the Stash variable with segment_2 which translates to "print" works and pulls in the image. So it's definitely a parse order issue. How can I get Stash to parse '{stash:entry_{entry_id}_category}' first before parsing the outer tag pair?

Thanks!

2

Stash parses any known {stash:variable} style markers at the beginning of each pass of the tagdata it wraps (working from the top layers of tags inwards). However {stash:entry_{entry_id}_category} does not resolve to a known stash variable until after {entry_id} has been parsed by the channel entries tag. By which point the channel entries tag has completed parsing and it's too late.

I would instead use nested stash lists:

{!-- set a list of entries, the first assinged category and all possible images fields --}
{exp:stash:set_list name="entries" parse_tags="yes" parse_depth="3"}
    {exp:channel:entries channel="resources" dynamic="no" limit="6" disable="member_data|pagination"}

        {!-- capture all the single value fields you need here --}
        {stash:entry_id}{entry_id}{/stash:entry_id}
        {stash:title}{title}{/stash:title}

        {!-- capture the category for the entry --}
        {exp:gwcode_categories entry_id="{entry_id}" depth="1" limit="1" style="linear"}
            {stash:cat_url_title}{cat_url_title}{/stash:cat_url_title}
        {/exp:gwcode_categories}

        {!-- capture images for every possible category here, assuming each is a custom field --}
        {exp:stash:set_list:nested name="category_print" context="{entry_id}"}
            {print_resource_images}
                {stash:url}{image:url:small}{/stash:url}
            {/print_resource_images}
        {/exp:stash:set_list:nested}

        {exp:stash:set_list:nested name="category_another" context="{entry_id}"}
            {another_resource_images}
                {stash:url}{image:url:small}{/stash:url}
            {/another_resource_images}
        {/exp:stash:set_list:nested}

        {!-- ...etc... --}

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


{exp:stash:get_list name="entries"}

    <h1>{title}</h1>

    {exp:stash:get_list:nested name="category_{cat_url_title}" context="{entry_id}" prefix="image"}
    <div class="thumb">
        <a href="#"><img src="{image:url}" alt=""></a>
    </div>
    {/exp:stash:get_list:nested}

{/exp:stash:get_list}
  • Thanks! Unfortunately it is outputting all the images collected by the "categories" and "tag_pairs" Stashes in one go, instead of only outputting one image per entry. Is there a way to Stash the category_url_title found per entry? * – Kerry Johnson Mar 4 '16 at 20:40
  • I updated the code, let me know how you get on. – Mark Croxton Mar 7 '16 at 18:09
  • Perfecto! Thanks so much for taking time out of your day to help me solve this, Mark! Now I can get rid of my {embed} and use this as a solution and a case for future Stash uses. – Kerry Johnson Mar 7 '16 at 19:57

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.