Skip to content

Bundles

Mark Croxton edited this page Jun 19, 2013 · 28 revisions

Bundles are categories for variables. 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 when creating variables, lists and embeds.

If you are using Mustash, you can create and manage your bundles in the Control Panel interface.

bundle="default"

This is the default place for all variables and lists that you create in your templates using the set/get syntax.

bundle="template"

This is the default bundle for all stash templates embedded with the {stash:embed} tag.

bundle="static"

This is the default bundle for all variables captured by the {exp:stash:static} tag.

Basic use

{exp:stash:set name="foo" bundle="my_custom_bundle"}bar{/exp:stash:set}

Saving form data to a custom bundle

The {exp:stash:bundle} tag can be used to save a group of variables into a single variable in a defined bundle. This is more efficient when saving a large number of form variables.

{!-- set a static context for the form values, which we can reference as '@' --}
{exp:stash:context name="my_search_form"}

{!-- register user-submitted values form the $_POST array, validate, and save to the '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$#"}
    {exp:stash:get dynamic="yes" type="snippet" name="category" default="" match="#^[a-zA-Z0-9_-]+$#"}
{/exp:stash:bundle}

{!-- now we could use like this in an embedded view template --}
<input name="orderby" value="{@:orderby}">

{!-- and if we wanted to populate a select menu --}

Cache-breaking

Bundles can be a useful when you need to clear a group of cached variables that are related in some way.

Clone this wiki locally