-
Notifications
You must be signed in to change notification settings - Fork 20
Bundles
Bundles are categories for variables. There are three default bundles: default, template and static, and you are able to create your own by specifying a name with the bundle=""
parameter when using the {exp:stash:bundle}
tag.
If you are using the Multiple Site Manager, be aware that Bundles are 'global' objects and the same bundles can be referenced across sites. Variables assigned to bundles are site-specific.
If you are using Mustash, you can create and manage your bundles in the Control Panel.
###Built-in bundles
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.
This is the default bundle for all variables captured by the {exp:stash:static}
tag.
{exp:stash:set name="foo" bundle="my_custom_bundle"}bar{/exp:stash:set}
When you need to persist form values across pages, the {exp:stash:bundle}
tag can be used to save a group of variables as a single variable in a defined bundle. This is much more efficient when saving a large number of independent form variables.
{!-- set a static context for the form values, which we can reference as '@' --}
{exp:stash:context name="my_search_form"}
{!-- register form values, validate individually, and save to a custom 'form' bundle --}
{exp:stash:bundle name="form" context="@" refresh="10" parse="inward"}
{exp:stash:get dynamic="yes" type="snippet" name="orderby" default="entry_date" match="#^[a-zA-Z0-9_-]+$#"}
{exp:stash:get dynamic="yes" type="snippet" name="sort" default="asc" match="#^asc$|^desc$#"}
{!-- multi-select fields get converted to a pipe-delimited string, e.g. 1|2|3 --}
{exp:stash:get dynamic="yes" type="snippet" name="category" default="" match="#^[0-9|]+$#"}
{/exp:stash:bundle}
{!-- now we could use like this in an embedded view template --}
{!-- note that the use of '@' pointers means we can reuse the form code elsewhere --}
<input name="orderby" value="{@:orderby}">
{!-- if we have captured an array of values in a variable we can use {if IN()} --}
{exp:stash:get_bundle name="form" context="{segment_3}"}
<select name="category">
{exp:channel:categories channel="entries" style="linear"}
<option value="{category_id}" {if '{category_id}' IN ({@:category})} selected="selected"{/if}>{channel_title}</option>
{/exp:channel:categories}
</select>
{/exp:stash:get_bundle}
Bundles can be a useful when you need to clear a group of cached variables that are related in some way.
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