Extension, Module

Archived
Forum
(read-only)

Stash

ExpressionEngine 2, ExpressionEngine 3, ExpressionEngine 4, ExpressionEngine 5, ExpressionEngine 6

Back to this add-on's main page
View Other Add-ons From Mark Croxton

     

Getting a List from another template

Support Request

digitalDesigns
digitalDesigns

We are setting a list in one template (and getting it in the same template) and everything is working as expected, however; when we try to get the same list in a different template we get no results. It is probably something super simple we are misunderstanding - but can you explain how we can set a list of data and get it from any template on the site?

This is working as expected:
system/expressionengine/templates/default_site/test/four.html

{!-- ====================================
FETCH THE DATA and STORE INTO A 'home-full-grid' VARIABLE
========================================= --}
{exp
:stash:set_list name="home-full-grid" parse_tags="yes" parse_depth="2" save="yes" scope="site" refresh="60" replace="no"}
{exp
:channel:entries channel="homes" status="Open|Featured|Slideshow|Rented" dynamic="no"}
        {stash
:house_link}{title_permalink="home"}{/stash:house_link}
        {stash
:house_image}{exp:channel_images:images entry_id="{entry_id}" field="home-cover"}{image:url:small}{/exp:channel_images:images}{/stash:house_image}
        {stash
:house_title}{title}{/stash:house_title}
{
/exp:channel:entries}
{
/exp:stash:set_list}

{
!-- ====================================
ASSEMBLE THE MARKUP
========================================= --}
 {exp
:stash:set}
 {stash
:home-grid}
 {exp
:stash:get_list name="home-full-grid"}
 
<a href="{house_link}"
  <
div class="grid-item" id="{switch="-|-|-|right"}">
   <
img class="thumb-img" src="{house_image}" width="200">
   <
div class="name">{house_title}</div>
  </
div><!--end grid item-->
 </
a>
 
{/exp:stash:get_list}
 {
/stash:home-grid}
    {
/exp:stash:set}
{embed
="test/layout"

This is not displaying any data (only displays the markup from the layout template)
system/expressionengine/templates/default_site/test/five.html

{!-- ====================================
ASSEMBLE THE MARKUP
========================================= --}


 {exp
:stash:set}
 {stash
:home-grid}
 {exp
:stash:get_list name="home-full-grid"}
 
<a href="{house_link}"
  <
div class="grid-item" id="{switch="-|-|-|right"}">
   <
img class="thumb-img" src="{house_image}" width="200">
   <
div class="name">{house_title}</div>
  </
div><!--end grid item-->
 </
a>
 
{/exp:stash:get_list}
 {
/stash:home-grid}
    {
/exp:stash:set}


{embed
="test/layout"

Thanks!

Mark Croxton
# 1
Developer
Mark Croxton

Just add scope=“site” to your get_list :)

Be careful though - this will only work if the first template is called before the second. You should really call the set code wherever you get the list, so the cache is rebuilt if it has been deleted or expired. Snippets are good for encapsulating ‘set’ code.