I'm just playing around with implementing Stash on a site, following the Template Partials Using Stash article, but now I seem to be having a scope/execution order issue.
Layout
<html>
<head>...</head>
<body>
<div id="container">
<div id="sidebar">
{exp:member:custom_profile_data}
{exp:stash:member_field_1}Foo{/exp:stash:member_field_1}
{exp:stash:member_field_2}Bar{/exp:stash:member_field_2}
{/exp:member:custom_profile_data}
</div>
<div id="content">
{exp:stash:content}
</div>
</div>
</body>
</html>
Content Partial
{embed="layouts/content"}
{exp:stash:content}
<div>
<h1>{exp:stash:member_field_1}</h1>
<h1>{exp:stash:member_field_2}</h1>
...
</div>
{/exp:stash:content}
I have some custom member fields that I need in a few places throughout my content sections, so I'm trying to retrieve them in the layout and assign them to variables, in the hopes that I could save my content from being littered with {exp:member] tags, but the variables don't seem to be available in my content partials.
I believe that it's not working because my Stash variables are being parsed before the values are assigned, and from what I believe I understand about the order of how EE is parsing the views, it goes something like this:
- Partial is retrieved
- Content is assigned to {exp:stash:content}
- Layout embed is retrieved
- Layout is parsed and {exp:stash:content} value injected.
Am I missing a feature/use-case of Stash, or am I simply using the wrong tool for this particular job?
Update: After racking my brain for days, and then writing this question, I tried saving the variable definitions in a snippet, which is called from my layout and it seems to work. I'd still be interested to know if there is a Stash implementation of this type of case, though.