0

I have a doubt about a Stash Embed parameter. In the Stash documentation page, there is this example:

{stash:embed name"my_var1" file_name="foo:bar" stash:my_var="value 1"}
{stash:embed name"my_var2" file_name="foo:bar" stash:my_var="value 2"}

I understood how it works, but I have a doubt about the name"my_var1" parameter. I do not understand the usefulness of this name"my_var1"

What is its function ? How to use it? What can I do with the my_var1 variable?

1

The example you have highlighted is intended to illustrate how you can take advantage of the stash caching system to create multiple cached versions of the same template code based on with different embed variable values. From the same documentation page that you clipped your example:

They can be nested, but unlike standard ExpressionEngine embeds you can use pre-parsing to assemble a single compiled cache of the rendered templates - which gives you all the benefits of encapsulation without the overhead

The idea behind this is that retrieving / inserting these cached embeds later / elsewhere in your template system as required will result in more rapid / less processor intense construction of the page, and so a more responsive site.

The names used (my_var1, my_var2) are generic values intended to illustrate the point, the names themselves have no specific meaning in this context.

The 'file_name' variable refers to the location of the template you want to use relative to the origin of your stash-templates directory - with the ':' symbol substituting for the '/' character.

The stash:my_var value refers to a value you want to pass to the embedded template - it is this difference that makes one cached version of the embed different from the other. Presumably you could have many variables listed if you prefer.

The documentation does not make clear how you would retrieve the stashed embed, but a good place to start would be using the standard syntax - i.e. {stash:embed name="my_var1"} - the documentation implying that the second time you call this the cached version will be retrieved.

HTH

| improve this answer | |
  • Hi Jcogs, thanks a lot for your great reply.Now my doubts are gone because your explanation It's very clear, well explained, and detailed. – Stéphane Apr 23 '18 at 14:08

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.