I'm trying to use Stash embeds on a pretty complex site and can 'see' a way to make things more DRY but can't actually figure out how to 'do'.

I have a collection of viewModal templates, that handle the various channels, and a lot of these channels share a naming convention for their right column meta data. In a perfect world, I would've shared these fieldgroups across the channels, but as that's not possible, I had to repeat myself a lot in the fields.

An example (stripped down slightly):

/editorial.html (viewModal template)

{!-- Set the page layout --}

{!-- Right side area [inject the rightcol_meta partial into the {stash:page_meta} region] --}
{exp:stash:set_value name="st_page_meta" value="{exp:stash:embed:partials:rightcol_meta}"}

{!-- Main content area --}
{exp:channel:entries limit="1" channel="editorial|structure_editorial" disable="member_data|pagination|categories" require_entry="yes"}

    {!-- (make all the meta fields snippets) --}
    {!-- Related links --}
    {exp:stash:set_list name="st_rel_links" parse_tags="yes"}

    {!-- Related publications --}
    {exp:stash:set_list name="st_rel_pubs" parse_tags="yes"}

    {!-- featureboxes (make all the meta fields snippets --}
    {exp:stash:set_list name="st_fbox_list" parse_tags="yes"}
        {!-- Heading style --}
        {!-- Image --}


I've surrounded the parts I'm talking about in *s (turns out I can't bold inside a code snippet). I want to be able to change these sections into snippets, and instead of {cf_editorial_rel_links} etc I would like to use {cf_{channel_short_name}_rel_links} so that in each viewModal I could just include 1 snippet. Even if I had to use {cf_{exp:stash:get name="channel_name"}_rel_links} it would be fine.

Is this possible? I think it is, but can't seem to get it to parse the channel short name (with stash or otherwise) in time for it to be processed correctly.

Thanks in advance for any help!


2 Answers 2


I'm afraid that won't work, because those relationship variable pairs are parsed by the channel entries tag before being captured by Stash. As the value of {channel_short_name} cannot be known until the channel entries tag has been parsed you cannot dynamically determine the name of the variable pairs.

What you could do however is make the code inside the variable pairs into a snippet:

  • Hi Mark, thanks for getting back to me. I do actually know the channel short name for each viewModel, so can I stash get inside a set list? I'm off to experiment now :)
    – Rob Hodges
    Commented Mar 18, 2013 at 9:37

OK, so I managed to solve this.

In the viewModel template, I've set a preload replace variable:

{!-- Used for right column meta data --}

At the top of the page, and then put the entire meta fields section, including the stash:set_list tags in one snippet: {sp_st_fields_page_meta}.

Inside that I can just use {pr_channel} and it will parse at the correct time, meaning that all these variables (21 in the real site) can be set for each viewModel (15, it is a huge site) with only one snippet :)

Hope this helps someone!

Your Answer

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

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