in your templates. Pass the output of one or more tags as the input to other tags. Change the order in which template tags and variables are parsed. Cache fragments of data, so that the tags that generated it do not need to be re-run on subsequent views. Variable
Set a variable - single tag {exp:stash:set_value name="foo" value="bar"} Set a multiple variables at once {exp:stash:set} {stash:title}A title{/stash:title} {stash:content}Some content{/stash:content} {/exp:stash:set} Se
Get a variable, provide a default value {exp:stash:get name="foo" default="bar"} Get a variable into a block {exp:stash:block name="foo"} Where are you two from, nose city? {/exp:stash:block} Ge
variable to a tag as a parameter... --} {exp:channel:entries url_title="{exp:stash:get name='url_title'}" channel="people" parse="inward"} {/exp:channel:entries} {!-- ...or, replace the variable into a tag --} {exp:stash:parse} {exp:channel:entries url_title="{stash:url_title}"} channel="people" {/exp:channel:entries} {/exp:stash:parse}
(default) The native Stash array. Can be ouput with placeholder {stash:my_var} inside Stash embeds & Stash tags. type="snippet" An EE snippet. Like other snippets, access as {my_var} inside EE embeds and use in advanced conditionals. Variabl t
Comparison - watch out for quotes! --} {if "{exp:stash:get name='person'}" == "Brian"} You silly sods! {/if} {!-- Is the variable empty? --} {if "{exp:stash:not_empty name='person'}"} He's not the Messiah. He's a very naughty boy! {/if} {!-- Switchee has native support --} {exp:switchee variable="stash:person" parse="inward"} {case value="Brian"} Blessed are the cheesemakers. {/case} {/exp:switchee}
{!-- Comparison --} {if person == "Brian"} You silly sods! {/if} {!-- Is the variable empty? --} {if person} He's not the Messiah. He's a very naughty boy! {/if} {!-- in an embed or inside {exp:stash:parse} --} {if person == "Brian"} I'm {person}, and so's my wife! {/if}
(a URI segment or entry_id), arbitrary ('my_context'), or an @ pointer: context="@URI" Points to the full URI of the current page. context="@" Points to the current static context set by the {exp:stash:context name="my_context"} tag. Cont
{exp:channel:entries channel="staff"} {exp:stash:append name="staff" context="{cf_dept}"} {cf_first_name} {cf_last_name}, {/exp:stash:append} {/exp:channel:entries} {!-- get staff members in the 'dogsbody' dept --} {exp:stash:get name="staff" context="dogsbody"} {!-- context is just a prefix. Same output: --} {exp:stash:get name="dogsbody:staff"} {!-- use @ pointers to make your code DRY --} {exp:stash:context name="dogsbody"} {exp:stash:get name="@:staff"}
is found, parse it first If a plugin tag is found, check for descendents... Results in parse order from innermost outwards Parse="inward" makes plugin behave like a module Plugi ta pars order
vars Simple conditionals PHP on input Preload replace vars {exp:tag}tag vars{/exp:tags} (Stash: process="inline") PHP on output Advanced conditionals Embeds (recursive) Stash: process="end" Redirect, user defined & standard globals Templat pars order 1 2 3 4 5 6 7 8 9
{/exp:channel:entries} {!-- by jove, it works! Unbag the kittens! --} {exp:stash:get name="content" default="if you can see this, it's not working!" process="end"}
variable if it already exists? refresh="X" (1440) Number of minutes to cache the variable until it expires. {stash:nocache}Don't cache me{/stash:nocache} Region remains unparsed until it is retrieved. Cachin option
memory. Expires once the page has rendered. scope="site" Globally visible to all. Set once until expires or replaced. scope="user" Linked to the user's session ID, only visible to that user. Expires when the user’s browser session ends. Scop
contrast</option> </select> </form> {!-- save the form value for the user's session --} {exp:stash:get name="contrast" scope="user" save="yes" match="#^s$|^hc$#" default="s" dynamic="yes"}
template performance. Sort, randomise, paginate, fractionalise and filter with regular expressions, in ways that go far beyond what is possible with standard tag pairs such as channel entries. Nested lists allow you to capture multi-dimensional arrays, such as a Playa tag nested within a Matrix. List
Creosote{/stash:name} {stash:job}Gluttony{/stash:job} {/exp:stash:set_list} Append / prepend a row to create a two-dimensional list {exp:stash:append_list name="characters"} {stash:name}Norwegian Blue{/stash:name} {stash:job}Parrot (deceased){/stash:job} {/exp:stash:append_list} Se on dimensiona lis
ID: 31 1 Name: Mr Creosote Age: 62 Unique ID: 32 2 Object: Gourd Used for: Holy water Value: Half a dinare 1 Item: Stone Used for: Heretics Value : About one stone 2 Object: Wafer-thin mint Used for: Scoffing Value: Complimentary 1 Object: Chocolate frog Used for: Eating Value : 1 million pounds 2 Job: Not the Messiah Job: Gluttony
{name}</h1> <ul> {!-- Get the related entries list for each row --} {exp:stash:get_list:nested name="items" context="{entry_id}" prefix="related"} <li>{related:count} : {item}</li> {/exp:stash:get_list:nested} </ul> {/exp:stash:get_list}
{name}</h1> <ul> {!-- Get the related entries list for each row --} {exp:stash:get_list:nested name="items" context="{entry_id}" prefix="related"} <li>{related:count} : {item}</li> {/exp:stash:get_list:nested} </ul> {/exp:stash:get_list} 2 1
10.6 Lodewijk Schutte 11.1 Eric Lamb 12.8 Runner Time Mrs Flinger 19.1 Eric Lamb 19.3 Justin Kimbrell 20.6 Carl W Crawley 21.1 Erik Reagan 22.2 Runner Time Brandon Kelly 43.2 Steven Grant 43.7 Jack McDade 44.6 Paulo Elias 46.8 Adrian Macneil 47.2 Runner Time m 400m Adrienne L. Travis 1:40.9 Iain Urquhart 1:41.5 Nicholas Bottari 1:42.4 Rob Sanchez 1:45.8 Ryan Masuga 5:25.5 Runner Time 800m 200m
100m, 200m, 400m --} {exp:stash:get_list name="race_data" scope="site" unique="distance"} <table> <caption>Results for {distance}</caption> <tr> <th>Runner</th> <th>Time</th> </tr> {!-- for each unique distance show runners and their time in order --} {exp:stash:get_list:nested name="race_data" scope="site" prefix="result" orderby="time" match="#^{distance}$#" against="distance"} <tr> <td>{result:runner}</td> <td>{result:time}</td> </tr> {/exp:stash:get_list:nested} </table> {/exp:stash:get_list}
Stash effectively. Set, get, append and prepend template variables; pass to tags, use in conditionals. Use scope to determine variable visibility, context and @pointers to namespace and re-use variables. Subvert parse order with post-processing & Stash parsing. Capture multi-dimensional lists from looping tag pairs and use nesting and filtering to group and multi-sort your data. Cache variables and lists to speed up your templates. Summar