-
Notifications
You must be signed in to change notification settings - Fork 20
Mapping custom fields to a common nomenclature
Mark Croxton edited this page Aug 20, 2013
·
2 revisions
When you have multiple channels with different field groups, but several duplicate fields. For example:
- products_bikes
- products_skateboards
- products_trikes
- bikes_summary
- skateboards_summary
- trikes_summary
Map the duplicate fields so that they can be referenced with a common name:
{!-- make a list of your channel prefixes --}
{exp:stash:set_list name="channels"}
{stash:channel}products_bikes{/stash:channel}
{stash:channel}products_skateboards{/stash:channel}
{stash:channel}products_trikes{/stash:channel}
{/exp:stash:set_list}
{!-- make a list of your common field suffixes --}
{exp:stash:set_list name="fields"}
{stash:field}summary{/stash:field}
{stash:field}another_field{/stash:field}
{/exp:stash:set_list}
{!-- map channels and fields to generate tag pairs --}
{exp:stash:set name="mapped_fields" parse_tags="yes" parse_depth="2" type="snippet"}
{exp:stash:get_list name="fields"}
{stash:{field}}
{exp:stash:get_list:nested name="channels"}
{{channel}_{field}}
{/exp:stash:get_list:nested}
{/stash:{field}}
{/exp:stash:get_list}
{/exp:stash:set}
{!-- capture the data --}
{exp:stash:set parse_tags="yes" type="snippet"}
{exp:channel:entries
channel='{exp:stash:get_list name="channels" backspace="1"}{channel}|{/exp:stash:get_list}'
parse="inward"
}
{mapped_fields}
{/exp:channel:entries}
{/exp:stash:set}
{!-- example of using the data in your view template (Stash embed or EE embed) --}
{if summary}{summary}{/if}
{!-- example of using the data in the *same* template you capture the data --}
{if summary}{exp:stash:get name="summary" type="snippet"}{/if}
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