-
Notifications
You must be signed in to change notification settings - Fork 20
Replacing matrix image slugs into another field
Mark Croxton edited this page Aug 22, 2013
·
8 revisions
Replace {image_n} tags in a content field when capturing multiple entries as a list:
{exp:stash:set_list name="blog_list" parse_tags="yes" parse_depth="2"}
{exp:channel:entries channel="blog" limit="5"}
{stash:item_title}{title}{/stash:item_title}
{stash:entry_date}{entry_date format="%F %j%S %Y"}{/stash:entry_date}
{!-- Tag pair for Matrix field named 'blog_images' --}
{blog_images}
{exp:stash:set name="image_{row_count}" type="snippet"}
<img src="{image_file:url}">
{/exp:stash:set}
{/blog_images}
{!-- Parse body field at this stage in order to separately capture all the Matrix field images per entry --}
{exp:stash:parse parse_vars="yes"}
{stash:item_body}{blog_body}{/stash:item_body}
{/exp:stash:parse}
{/exp:channel:entries}
{/exp:stash:set_list}
{exp:stash:get_list name="blog_list"}
<h1>{title} - Posted on {entry_date}</h1>
{body}
{/exp:stash:get_list}
When pagination is required:
{exp:stash:set_list name="blog_list" parse_tags="yes" parse_depth="2"}
{exp:channel:entries channel="blog" limit="5" paginate="bottom"}
{stash:title}{title}{/stash:title}
{stash:entry_date}{entry_date format="%F %j%S %Y"}{/stash:entry_date}
{!-- Tag pair for Matrix field named 'blog_images' --}
{blog_images}
{exp:stash:set name="image_{row_count}" type="snippet"}
<img src="{image_file:url}">
{/exp:stash:set}
{/blog_images}
{!-- Parse body field at this stage in order to separately capture all the Matrix field images per entry --}
{exp:stash:parse parse_vars="yes"}
{stash:body}{blog_body}{/stash:body}
{/exp:stash:parse}
{paginate}
{exp:stash:set_list:nested name="pagination"}
{stash:current_page}{current_page}{/stash:current_page}
{stash:total_pages}{total_pages}{/stash:total_pages}
{pagination_links}
{previous_page}{stash:previous_page}{pagination_url}{/stash:previous_page}{/previous_page}
{stash:pages}{page}<a href="{pagination_url}"style="font-weight:bold">{pagination_page_number}</a>{/page}{/stash:pages}
{next_page}{stash:next_page}{pagination_url}{/stash:next_page}{/next_page}
{/pagination_links}
{/exp:stash:set_list:nested}
{/paginate}
{/exp:channel:entries}
{/exp:stash:set_list}
{exp:stash:get_list name="blog_list"}
<h1>{title} - Posted on {entry_date}</h1>
{body}
{/exp:stash:get_list}
{exp:stash:get_list name="pagination"}
Page {current_page} of {total_pages} | {if previous_page}<a href="{previous_page}">Prev</a> | {/if} {pages}{if next_page} | <a href="{next_page}">Next</a>{/if}
{/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