Skip to content

{exp:stash:bundle}

Mark Croxton edited this page Jun 21, 2013 · 1 revision

Bundle up a group of independent variables into a single variable and save to the database. If the bundled variable already exists then the bundle is retrieved and the individual variables are restored into the current session.

This is very useful when working with form field values that you want to register from a dynamic source such as $_POST or $_GET, validate the user submitted form value against a regular expression, and persist the submitted value from page to page. Instead of saving multiple variables you can efficiently bundle them up into one variable requiring only a single query for retrieval.

Parameters

name = [string]

The name of your bundle (required)

unique = ['yes'|'no']

Do you only want to allow one entry per bundle? (optional, default is 'no')

context = [string]

Define a context for the bundled variables (optional)

refresh = [int]

This parameter sets the number of minutes to store the bundle (optional, default is 1440 - or one day)

Example usage

{exp:stash:context name="my_search_form"}

{exp:stash:bundle name="form" context="@" refresh="10" parse="inward"}
	{exp:stash:get dynamic="yes" type="snippet" name="orderby" output="yes" default="entry_date" match="#^[a-zA-Z0-9_-]+$#"}
	{exp:stash:get dynamic="yes" type="snippet" name="sort" output="yes" default="asc" match="#^asc$|^desc$#"}
	{exp:stash:get dynamic="yes" type="snippet" name="category" output="yes" default="" match="#^[a-zA-Z0-9_-]+$#"}
{/exp:stash:bundle}

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