1

I'm trying to use Stash to replace {image_n} tags in the content fields, like also mentioned on:

using Stash to replace Matrix image slugs

http://devot-ee.com/add-ons/support/stash/viewthread/3013

I get that working just fine but when I try this on a page with multiple entries, the images simply show the same matrix images (of the first entry) and not different images per entry. I'm assuming this is due to the images being saved as snippets, so I figured instead of that, adding a context to the stashed data would do the trick, but I just can't get it to work. Can anyone help me out? Here's what I have now:

{exp:stash:set_list name="bloglist" parse_tags="yes" parse_depth="2"}
    {exp:channel:entries channel="blog" limit="5"}

        {stash:item_title}{title}{/stash:item_title}
        {stash:item_entry_id}{entry_id}{/stash:item_entry_id}{!-- For potential use as context --}
        {blog_images}
            {exp:stash:set name="image_{row_count}" type="snippet"}
                <img src="{image_file:url}">
            {/exp:stash:set}
        {/blog_images}
        {stash:item_body}{blog_body}{/stash:item_body}

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


{exp:stash:get_list name="bloglist" parse_vars="yes"}

    <h1>{item_title}</h1>
    {item_body}

{/exp:stash:get_list}

1 Answer 1

1

The problem you're having is that you are setting the value of {image_x} on each iteration of the channel entries loop, overwriting the value saved in the previous iteration. One approach you could try would be to parse the placeholders in the {blog_body} field immediately after setting the variables in an iteration, and before the whole list is captured:

{exp:stash:set_list name="bloglist" parse_tags="yes" parse_depth="2"}
    {exp:channel:entries channel="blog" limit="5"}

        {stash:item_title}{title}{/stash:item_title}
        {stash:item_entry_id}{entry_id}{/stash:item_entry_id}

        {blog_images}
            {exp:stash:set name="image_{row_count}" type="snippet"}
                <img src="{image_file:url}">
            {/exp:stash:set}
        {/blog_images}
        {exp:stash:parse parse_vars="yes"}
            {stash:item_body}{blog_body}{/stash:item_body}
        {/exp:stash:parse}

    {/exp:channel:entries}  
{/exp:stash:set_list}
3
  • Thanks so much for that answer, works like a charm and helps a great deal in my understanding of Stash! You really should have a tip jar somewhere, I'd be happy to help support your development of Stash.
    – Jolle
    Jul 10, 2013 at 12:51
  • Oh, and two small typos I believe I found in the the documentation, on github.com/croxton/Stash/wiki/Lists under "Three (and more) dimensional lists": 1. {stash:item_entry_id}{title}{/stash:item_entry_id} : {entry_id} instead of {title} 2. {exp:stash:get name="my_list"} : exp:stash:get_list instead of exp:stash:get
    – Jolle
    Jul 10, 2013 at 12:56
  • Good catch, I've corrected those typos. Jul 10, 2013 at 17:32

Your Answer

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

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