I want to update a variable based on my module. I can pass the variable from the main template (say A) to the embedded one(say B). But how can I retrieve this variable back in Template A after updating the variable from B.

Or is there any other way to use a variable in a template and gets updated from a module and the updated variable to be used in the proceeding exp: calls to the module?

When I try to update the variable, I always get the first assigned value.I think the issue is with the parse order.

If anyone knows, please help how to handle this requirement.


2 Answers 2


Embeds are normally parsed at the end.
You can try setting a variable with Stash.
In the main-template get the variable at process-end.

A better approach is to use stash to store your data
in the first place, and avoid an extra embed altogether.

// template1 -----------------------------------------
{exp:stash:set name="myvar"}value1{/exp:stash:set}
<p>The value is: {exp:stash:get name="myvar" process="end"}</p>

// template2 -----------------------------------------
<h2>The embed</h2>
<p>myvar: {exp:stash:get name="myvar"}</p>
{exp:stash:set name="myvar"}value-embed{/exp:stash:set}

// output --------------------------------------------
The value is: value-embed
The embed
myvar: value1
  • Thanks. But one question. Can we get the updated variable at the beginning of each embedded templates? Since we are giving process = end, does the change for the value reflect at the end of html rendering? Please reply
    – Dhanu
    Nov 4, 2013 at 11:22
  • i've editted the example. When you get:myvar in the embed before setting it again, you will get the current value. You can also set it as a snippet, pass it as a parameter to embed= and if you need it as a parameter for another tag in the embed, you can wrap that tag with a stash:get pair. Success
    – GDmac
    Nov 4, 2013 at 12:14

If you need to modify the variable in the process of template parsing, I would suggest creating a plugin that will utilize EE Session cache.

Depending on your exact needs, you may find Low Variables useful as well.

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.