I've got an interesting problem that is leading me to believe I am approaching things totally wrong with stash... Essentially I am trying to call a "get_list" inside a variable that I am using as a placeholder in the layout.
Here is what I am trying to do:
I have a layout that I share across the site
<!DOCTYPE html>
{stash:embed:partials:global_html}
<head>
{stash:embed:partials:global_html_head}
</head>
<body class="{stash:body_class}">
<div class='container shadow'>
<header class='header-page' role='banner'>
{stash:embed:partials:global_html_header}
</header>
<!-- /END #Header -->
<section class='content' role='main'>
{!-- Define the primary content or listing in the model. --}
{if {exp:stash:not_empty name="content-primary"}}
<article class='content-main'>
{exp:stash:content-primary}
</article>
<!-- /END .content-main -->
{/if}
</section>
<!-- /END section .content -->
<section class='sidebar-page' role='complementary'>
<h3>Sidebarpaloooooza</h3>
</section>
<!-- /END .sidebar-page -->
</div>
<!-- /END .container -->
<footer class='footer-page container' role='contentinfo'>
{stash:embed:partials:global_html_footer}
</footer>
</body>
<!-- /END .body_class -->
</html>
In the layout I have placeholder variables to grab data from my models for display in the layout:
{!-- Define the primary content or listing in the model. --}
{if {exp:stash:not_empty name="content-primary"}}
<section class='content-main'>
{exp:stash:content-primary}
</section>
<!-- /END .content-main -->
{/if}
</section>
<!-- /END section .content -->
In my model I am grabbing a nested list of entries
{exp:stash:set_list
name="listing"
parse_tags="yes"
parse_depth="2"
}
{exp:channel:entries
channel="ch_company_location"
dynamic="no"
{global:param_disable_default}
}
{stash:some_var}{cf_var_goes_here}{/stash:some_var}
{!-- This is a Matrix Field --}
{exp:stash:set_list:nested name="employees"}
{cf_matrix_field}
{stash:var_one}{cf_var_1}{/stash:var_one}
{stash:var_two}{cf_var_2}{/stash:var_two}
{stash:var_three}{cf_var_3}{/stash:var_three}
{/cf_matrix_field}
{/exp:stash:set_list:nested}
{/exp:channel:entries}
{/exp:stash:set_list}
What I can't wrap my head around is how to get conditionals, {count}, {switch}, and {total_results} to work in when defining {exp:stash:content-primary}:
{!-- Primary content area --}
{exp:stash:set
name="content-primary"
output="no"
parse_conditionals="yes"
parse_tags="no"
parse_vars="yes"
}
{exp:stash:get_list
name="listing"
prefix ="parent"
}
{exp:stash:get_list:nested
name="employees"
prefix ="emp"
}
{if emp:count == 1}
<div class="employees">
{/if}
<div class="employee {emp:switch="first||last"}">
<dl>
<dt>{var_one}</dt>
<dd>{var_one}</dd>
<dd>var_one</dd>
</dl>
</div>
{if emp:count == emp:total_results}
</div>
<!-- /END .employees -->
{/if}
{/exp:stash:get_list:nested}
{/exp:stash:get_list}
{/exp:stash:set}
No matter what I do I trigger the following errors:
Parse error: syntax error, unexpected ':' in /system/expressionengine/libraries/Functions.php(683) : eval()'d code on line 9
or
A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant count - assumed 'count'
Filename: libraries/Functions.php(683) : eval()'d code
Line Number: 9
I've tried parent:switch/parent:count/parent:total_results and just plain old {switch}/{count}/{total_results} in addition to the "emp:*" to no avail.
Am I approaching this incorrectly? Is there a way to define global "buckets" that I can load stash variables, lists, and nested lists into inside my layout(s)?
I'm using:
- EE 2.5.5
- Matrix 2.5.5
- Stash 2.3.6
parse_tags
need to beyes
in your{exp:stash:set name='content-primary'}
? – Jason Varga Jun 19 '13 at 2:10