Closed timkelty closed 11 years ago
The good news is that Stash already does this (kind of). Stash embeds are saved into memory as native Stash variables, and you can access them at any point after the template has been embedded:
{exp:stash:get name="tab_products"}
Note that is is equivalent to the following:
{exp:stash:embed name="tab_products" process="inline"}
In both cases the value is read from memory, a new query or file-read is not required.
Or within a template parsed by Stash:
{stash:tab_products}
In your case you want to want to include the embed and capture it's parsed value, rather than the value before parsing. For this you can use the parse_stage="set" parameter. Note that you would need to pass any field values captured from the channel entries tag to the embed via stash:my_var parameters:
{exp:channel:entries
disable="categories|category_fields|member_data|pagination|trackbacks"
dynamic="yes"
require_entry="yes"
}
{stash:embed:tab_products
process="inline"
parse_stage="set"
stash:field="{cf_store_product_suggested}"
}
{/exp:channel:entries}
{!-- you need to access later in the parse order of the template if using in same template, hence process="end" --}
{exp:stash:get name="tab_products" process="end"}
If you are trying to pass values that may contain quotes, you could do this:
{exp:channel:entries
disable="categories|category_fields|member_data|pagination|trackbacks"
dynamic="yes"
require_entry="yes"
}
{exp:stash:set}
{stash:store_product_suggested}{cf_store_product_suggested}{/stash:store_product_suggested}
{/exp:stash:set}
{stash:embed:tab_products
process="inline"
parse_stage="set"
}
{/exp:channel:entries}
{!-- you need to access later in the parse order of the template if using in same template, hence process="end" --}
{exp:stash:get name="tab_products" process="end"}
Brilliant! Thanks Mark.
I find myself often using stash:embeds for code reuse.
I find myself doing this alot:
What do you think about adding a param to to stash:embed save the output to a stash var? Or maybe use the output param? So it might look like:
Does that make sense?