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

process="end" not working as expected #93

Closed alycda closed 10 years ago

alycda commented 10 years ago

I have reviewed your slideshow (per my last issue) but I'm still confused on the following:

/default_site/index.html

{exp:channel:entries url_title="{pre_lang}" dynamic="no"}
  {exp:stash:set name="native"}{native}{/exp:stash:set}
  ...
{/exp:channel:entries}

{stash:embed:partials:head}
{stash:embed:layouts:home}
{stash:embed:partials:footer}

/default_site/_stash/partials/head.html

<meta charset="utf-8">
...
{stash:extra-meta}

/default_site/_stash/layouts/home.html

...
{exp:stash:set name="extra-meta"}
<link rel="stylesheet" href="_/css/home.css">
{/exp:stash:set}

{exp:stash:set name="extra-js"}
<script>
$(function(){
 console.log('extra js for home')
});
</script>
{/exp:stash:set}

/default_site/_stash/partials/footer.html

...
{exp:stash:extra-js}

here's why I'm confused. the extra-meta variable properly retrieves the value set from layouts/home but the extra-js variable returns nothing. So the first thing I tried is adding process="end" to the footer embed, but that didn't work. I could add process="inline" to layouts/home (which works) but then the stash variables I set in index.html aren't available. I also tried adding process="end" to layouts/home but that doesn't work. I then tried adding process="end" to {exp:stash:get name="extra-js"} and that didn't work. what finally worked is {exp:stash:get name="extra-js" process="end"} in the index.html file. what I don't understand is why I can't add process="end" to the footer embed, or why the head embed works (since it comes before the home embed) which must be due to parse order, but is confusing because it's not top-to-bottom like I expect with PHP (I know there are benefits to this, it's just confusing with so many stages).

croxton commented 10 years ago

Parse order is linear but only within a single 'layer' of tags. Each layer of tags is parsed and 'peeled off' like an onion to expose layers underneath which are then parsed in turn. In other words, EE parsing is recursive rather than completely linear like a scripting language.

If you want to determine the precise order of parsing of your Stash embeds (or indeed any Stash tag that is processed at the end of template parsing with process="end") then you can use the priority="x" parameter, where x is an integer. The higher the value of x the later the tag will be parsed.