Stash
ExpressionEngine 2, ExpressionEngine 3, ExpressionEngine 4, ExpressionEngine 5, ExpressionEngine 6
Back to this add-on's main page
View Other Add-ons From Mark Croxton
store an embed template into a stash variable
Support Request
pixi
|
Posted: 04 December 2013 11:09 AM |
|
|
|
Hi,
Can you tell me how to store the ‘result’ of an embed template in a stash variable please ?
Some explanations :
I try to do a math with MX Calculator plugin with a stash variable as value but the variable isn’t understandable by the plugin because it doesn’t store the embed template but the tag of the embed template.
(for information the embed template contains the number 10).
{loop}
{exp:stash:set name="foo{count}"} {embed="administratif/.total_htva"} {/exp:stash:set}
{exp:stash:parse process="end" parse_tags="yes"} result = {exp:mx_calc expression="({stash:foo{count}}*3)" parse="inward"}{calc_result}{/exp:mx_calc} {/exp:stash:parse}
{/loop}
No result.
The template debugger outputs this :
{exp:mx_calc expression="({embed="administratif/.total_htva"}*3)" parse="inward"}
But if I hardcode myself by putiing 10 in place of {embed=“administratif/.total_htva”} in the set stash tags it outputs 30 as a result.
As you can see in the debugger it replace the stash by 10, as expected :
{exp:mx_calc expression="(10*3)" parse="inward"}
That’s what I want.
Can you help me please ? Thanks.
|
|
|
Mark Croxton
|
Posted: 04 December 2013 11:32 AM |
# 1
|
|
Developer
|
Stash doesn’t parse EE embeds, and if you remove them from the template then EE can’t parse them either. Embeds are in any case parsed after tags, so you can;t pass them as parameters.
So you really need an embed? If a snippet won’t do, use a Stash embed instead.
https://github.com/croxton/Stash/wiki/Embeds
Stash embeds are variables, so you can do this:
{stash:embed name="my_total" file_name="administratif:total_htva" process="inline"} {exp:mx_calc expression="({exp:stash:my_total}*3)" parse="inward"}
Because you’re passing it as a param, just makes sure your embed doesn’t return line breaks, or remove them with trim=“yes” when you get the var {exp:stash:my_total trim=“yes”}
|
|
|
pixi
|
Posted: 05 December 2013 05:35 AM |
# 2
|
|
|
Thanks for your answer Mark,
we had a little progress in the problem but we still have one :
We did as you said :
{loop}
{stash:embed name="my_total{count}" file_name="_stash:total_htva_stash" stash:collection_name="acompte{count}" process="inline"} result = {exp:mx_calc expression="({exp:stash:my_total{count}}*3)" parse="inward"}{calc_result}{/exp:mx_calc}
{/loop}
As long as my embed stash template contains a number (‘10’ for example), he retrieve the value and does the math. result = 30.
But, when I put other things in my embed stash template, for example {stash:collection_name} what I have in the debugger is :
RETRIEVED my_total1 with value {stash:collection_name}
.
{exp:mx_calc expression="({exp:stash:my_total1}*3)" parse="inward"}
(I know he can’t do the math with a name but it is to show you that it doesn’t parse the things contained in the embed stash template, so I can’t use the result of an embed to do things.
|
|
|
pixi
|
Posted: 09 December 2013 06:50 AM |
# 3
|
|
|
Any idea ?
|
|
|
Mark Croxton
|
Posted: 09 December 2013 07:04 AM |
# 4
|
|
Developer
|
Please can you post the contents of your embed.
|
|
|
pixi
|
Posted: 09 December 2013 07:32 AM |
# 5
|
|
|
10
it is a value to test stash (to test math etc…) because at the end I’ll have to put this :
{exp:tally:total collection="{stash:collection_name}" decimals="2"}
http://devot-ee.com/add-ons/tally
|
|
|
Mark Croxton
|
Posted: 10 December 2013 09:10 AM |
# 6
|
|
Developer
|
RETRIEVED my_total1 with value {stash:collection_name}
I think I understand your confusion. The above is exactly what you should expect. The embed is saved as a variable and parsed *on retrieval* (the ‘GET’ stage) - and the parsed value returned to the host template. This behaviour is determined by the parse_stage (GET by default, like an EE embed):
https://github.com/croxton/Stash/wiki/{stash:embed}#parse_stage—-set—get—both-
You can change the parse stage to SET if you want to save the embed variable with the parsed value:
{stash:embed name="my_total{count}" file_name="_stash:total_htva_stash" stash:collection_name="acompte{count}" process="inline" parse_stage="set"}
|
|
|