croxton / Stash

Stash allows you to stash text and snippets of code for reuse throughout your templates.
GNU General Public License v3.0
197 stars 20 forks source link

How to 'overwrite existing EE global variables' #89

Closed alycda closed 10 years ago

alycda commented 10 years ago

Hi, is it possible to use stash to override a global variable without using an EE embed? I did the following test:

{exp:stash:set name="my_var" type="snippet"}Value{/exp:stash:set}
{my_var} | {exp:stash:get name="my_var" type="snippet"}

and found that only the second variable will return the intended result, unless I place the second line in an EE template and call with an embed:

{embed="site/_test"}

What I want to achieve is setting default variables as a global var, something like a standard page title, but when I loop through channels and set Stash variables, I want to be able to override global variables, if the stash variable is not empty. I'm putting the global variable that I want to override in a snippet (i would use a stash embed, but in this case a very simple snippet is my preferred choice, also, sometimes I want to parse PHP which stash can't handle).

alycda commented 10 years ago

found it! {exp:stash:parse process="end"}. I'm still very new to all of this so if you have any insight, about this, I'd appreciate it.

croxton commented 10 years ago

You may find the slides from this presentation I gave last year to be helpful. Particularly the example following slide 17. Basically, it all comes down to parse order: https://speakerdeck.com/croxton/stash-core-principles