-
Notifications
You must be signed in to change notification settings - Fork 20
{exp:stash:set_list}
Set an array of key/value pairs, defined by stash variable pairs {stash:my_key}my_value{/stash:my_key}
.
Automatically detects and captures multiple rows of variables pairs, so can be used to capture data from tags and tag pairs that loop.
{exp:stash:set_list name="my_list"}
{stash:item_title}My title{/stash:item_title}
{stash:item_summary}Summary text{/stash:item_summary}
{stash:item_copy}Bodycopy goes here{/stash:item_copy}
{/exp:stash:set_list}
Accepts the same parameters as {exp:stash:set}, with the following changes / additions:
Match a column in the list against a regular expression. Only rows in the list that match will be appended to the list.
Column to match against. If against is not specified or is not a valid list column, match="#regex#"
will be applied to the whole block of tagdata passed to set_list.
Prefix for {if no_results}
, e.g. {if my_prefix:no_results}
{exp:stash:set_list name="my_products" parse_tags="yes"}
{exp:channel:entries channel="products"}
{stash:item_title}{title}{/stash:item_title}
{stash:item_summary}{summary}{/stash:item_summary}
{stash:item_copy}{copy}{/stash:item_copy}
{/exp:channel:entries}
{/exp:stash:set_list}
{exp:channel:entries channel="blog" entry_id="123"}
{exp:stash:set_list name="blog_related_entries" parse_tags="yes" save="yes" scope="site"}
{blog_related}
{stash:item_title}{title}{/stash:item_title}
{/blog_related}
{/exp:stash:set_list}
{/exp:channel:entries}
{exp:stash:set_list name="recent_discussion_topics" parse_tags="yes" match="#^A#" against="topic_title"}
{exp:forum:topic_titles
orderby="post_date"
sort="desc"
limit="5"
forums="1"
}
{stash:topic_url}{thread_path='forum/viewthread'}{/stash:topic_url}
{stash:topic_title}{title}{/stash:topic_title}
{stash:last_author_url}{last_author_profile_path='member'}{/stash:last_author_url}
{stash:last_author_name}{last_author}{/stash:last_author_name}
{stash:last_post_date}{last_post_date}{/stash:last_post_date}
{/exp:forum:topic_titles}
{/exp:stash:set_list}
{exp:stash:set_list name="my_entries" parse_tags="yes" parse_depth="2"}
{exp:channel:entries channel="clients" limit="5"}
{stash:entry_title}{title}{/stash:entry_title}
{stash:entry_id}{entry_id}{/stash:entry_id}
{exp:stash:set_list:nested name="related_entries_{entry_id}" parse_tags="yes"}
{!-- this is a matrix tag pair --}
{contact_docs}
{stash:related_title}{mx_doc_title}{/stash:related_title}
{/contact_docs}
{/exp:stash:set_list:nested}
{/exp:channel:entries}
{/exp:stash:set_list}
{exp:stash:get_list name="my_entries"}
Entry title: {entry_title}
Related:
{exp:stash:get_list:nested name="related_entries_{entry_id}"}
{related_title}
{/exp:stash:get_list:nested}
{/exp:stash:get_list}
no_results should ideally be handled by get_list, however it is possible to set a variable within the no_results block
{exp:stash:set_list parse_tags="yes" name="my_entries"}
{exp:channel:entries
channel="clients"
limit="20"
}
{stash:entry_title}{title}{/stash:entry_title}
{stash:entry_id}{entry_id}{/stash:entry_id}
{if no_results}
{exp:stash:set name="my_message"}No results{/exp:stash:set}
{/if}
{/exp:channel:entries}
{/exp:stash:set_list}
{exp:stash:get name="message" default="Showing results"}
{exp:stash:get_list name="my_entries" limit="5"}
{entry_title} ({entry_id})
{/exp:stash:get_list}
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