0

I'm working on an XML template for a site and need to output a series of listings where URLs look like:

/store/#type#/#brand#/#collection#/

My entries are set up so that there's an entry for each brand with a matrix row for each collection (type is a category of the entry).

So I need to loop through the entries in the channel and then loop through the matrix rows for each entry and output a <url> pair for all of them.

With the code below I get output if I don't have the exp:stash:get_list:nested tag (but with incorrect URLs), but with it, I get nothing.

{exp:stash:set_list
    name="collections"
    parse_depth="2"
    parse_tags="yes"
}
    {exp:channel:entries
        channel="brands"
        disable="member_data|pagination|trackbacks"
        dynamic="no"
    }
        {stash:collection_url_title}{url_title}{/stash:collection_url_title}

        {stash:collection_entry_id}{entry_id}{/stash:collection_entry_id}

        {stash:collection_type}{categories}{category_url_title}{/categories}{/stash:collection_type}

        {exp:stash:set_list:nested name="collection_{collection_entry_id}" parse_tags="yes"}
            {cat_images}
                {stash:collection_cat}{exp:cat2:url_title category_id='{cat}'}{/stash:collection_cat}
            {/cat_images}
        {/exp:stash:set_list:nested}

    {/exp:channel:entries}

{/exp:stash:set_list}

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

    {exp:stash:get_list:nested name="collection_{collection_entry_id}"}
        <url>
            <loc>http://www.domain.com.au/store/{collection_type}/{collection_url_title}/{collection_cat}/</loc>
        </url>
    {/exp:stash:get_list:nested}

{/exp:stash:get_list}

Anyone see where I'm going wrong?

  • Have you tried append_list? e.g. {exp:stash:append_list:nested name="collection_{collection_entry_id}" parse_tags="yes"} – Natetronn Apr 23 '14 at 2:35
  • Oh shouldn't {collection_entry_id} in {exp:stash:set_list:nested name="collection_{collection_entry_id}" parse_tags="yes"} actually be just {entry_id} i.e collection_{entry_id} – Natetronn Apr 23 '14 at 2:41
3

You need to use the context parameter and a unique identifier in your nested list. Generally using entry_id is the easiest way to create a relationship between your two lists.

  1. Stash {entry_id} in your outer list (used for retrieval wit get_list)
  2. Set the context parameter in your nested list and feed it {entry_id} from your outer list
  3. when getting your nested list, use the context parameter again and feed it the stashed {stash_entry_id} from step one.

Here is a detailed explanation and example on the Stash wiki.

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