-
Notifications
You must be signed in to change notification settings - Fork 20
Terminology
###Type
Stash can store variables in two different places:
A variable is stored in the Stash session, and can be retrieved using {exp:stash:get name="my_var"}
or {exp:stash:my_var}
A 'snippet' works just like snippets in ExpressionEngine, and can be used in the same way, e.g. {my_var}
. When using snippets it is possible to overwrite existing EE global variables in the current request. Note that EE snippets can also be retrieved using {exp:stash:get name="a_snippet" type="snippet"}
###Scope Scope refers to the visibility of a variable. An instance of the variable can be set for the current page only, for the current user, or globally for everyone that visits your site.
A 'local' variable exists in memory for the duration of the current HTTP request, and expires once the page has been rendered. It cannot be saved to the database.
A 'user' variable behaves like a local variable but can optionally be saved to the database for persistence across page loads (with save="yes"
). When saved, the variable is linked to the user's session id, and so it's content is only visible to that user. While a user-scoped variable can be set to expire after an arbitrary time period (with refresh=""
), by default it will expire anyway once the users' session has ended. For persistence of user-scoped variables beyond the user's current browser session set the 'stash_cookie_expire' configuration setting to the desired number of seconds.
Use for pagination, search queries, or chunks of personalised content that you need to persist across pages.
A 'site' variable is set only once until it expires, and is visible to ALL site visitors. Use for caching common parts of your template.
###Context Use contexts to namespace related variables and help organise and reuse your code. Contexts may be environmental (for example, the a URI segment or entry_id), arbitrary ('my_context'), or a pointer.
Pointers are references to a pre-existing namespace:
Points to the current static context set by the {exp:stash:context name="my_context"}
tag.
Points to the full URI of the current page.
Bundles are categories for variables that have been cached (when using save="yes"
with {exp:stash:set}
, or caching). There are three default bundles: default, template and static, and you are able to create your own simply by specifying a name with the bundle=""
parameter.
This is the default place for all variables and lists that you create in your templates using the set/get syntax.
This is the default bundle for all stash templates embedded with the {stash:embed}
tag, and page fragments captured by the {exp:stash:cache}
tag.
This is the default bundle for all variables captured by the {exp:stash:static}
tag. This bundle should only be used for full-page static caching, you cannot use it for page fragments.
When in the parse order of your host EE template an embed is included or the code wrapped by a stash tag is run.
Embed a template before any other variables and tags in your template are parsed.
Embed a template or get a variable/list in the natural parse order of the template (like a {exp:tag})
Embed a template or or get a variable/list at the end of template parsing after other tags and variables have been parsed.
Cache a template as a static file.
###Parse stage
When to parse the template: parse and cached, or cache then parsed on retrieval, or do both (default="get").
####parse_stage="set"
Parse the template the first time it is read from the file, and cache the rendered result. Subsequent retrievals will return the cached template from the database and not the original template file (unless replace="yes" or stash_file_sync = true).
####parse_stage="get"
Read the template file and cache it to the database. When output to the template on the first and subsequent retrievals the template will be parsed. This is similar to how EE templates work.
####parse_stage="both"
Parse the template before caching AND after it is retrieved. This can be very useful when enclosing regions of your template with {stash:nocache}{/stash:nocache}. On SET the template code inside {stash:nocache} will not be parsed, but everything else will. On GET it will be parsed. This provides a way to partially cache some of your template code while leaving other areas dynamic.
Getting started
Using Stash
Using Mustash
- Mustash
- Installing Mustash
- Managing variables
- Managing bundles
- Cache-breaking rules
- Mustash plugins
- Mustash Varnish plugin
- Mustash plugin development
- Mustash API
Template design patterns
Tag reference
- {exp:stash:set}
- {exp:stash:get}
- {exp:stash:block}
- {exp:stash:set_value}
- {exp:stash:append}
- {exp:stash:append_value}
- {exp:stash:prepend}
- {exp:stash:prepend_value}
- {exp:stash:copy}
- {exp:stash:context}
- {exp:stash:is_empty}
- {exp:stash:not_empty}
- {exp:stash:set_list}
- {exp:stash:get_list}
- {exp:stash:append_list}
- {exp:stash:prepend_list}
- {exp:stash:split_list}
- {exp:stash:join_lists}
- {exp:stash:list_count}
- {exp:stash:unset}
- {exp:stash:flush_cache}
- {exp:stash:bundle}
- {stash:embed}
- {exp:stash:extend}
- {exp:stash:parse}
- {exp:stash:cache}
- {exp:stash:static}
- {exp:stash:finish}
- {exp:stash:not_found}
- Short tag syntax
- Using Stash methods in your own add-ons