3

I am trying to use stash to kill multiple queries to the same channel in multiple places in the site/page. This is my stash embed file called 'featured.html':

        {exp:channel:entries channel="homepage_featured_items" dynamic="no" show_expired_entries="yes" orderby="date" category='40|41|42|162' disable="member_data|category_fields|pagination"}
      {exp:stash:append_list name='featured_list'}
        {stash:this_category}{categories}{category_id}{/categories}{/stash:this_category}
        {stash:article}
          <article class="col_4 col left">
              <header>
                <h4><a href="{featured_item_link}">{featured_short_text}</a></h4>
              </header>  
              <div class='article-content'> 
                <p><a href="{featured_item_link}">{featured_short_description}</a></p>
              </div>            
              {exp:ce_img:pair src="{featured_image_home}" width="220" height="150" crop="yes|center,top|0,0"}
                <img src="{made}" alt="{title}" width="{width}" height="{height}" />
              {/exp:ce_img:pair}    
          </article>
         {/stash:article}
      {/exp:stash:append_list}
    {/exp:channel:entries}

And I would like to bring different categories in like so:

<div id="featured_home">
    {exp:stash:embed:featured}
    {!-- 40,41,42,162 --}
    {exp:stash:get_list name="featured_list"  match="#^.*40.*$#" against="this_category" limit="1"}
      {article}
    {/exp:stash:get_list}
  </div>  

But for some reason I am getting nothing. I put output='yes' on my stash embed append_list tag and I got all of the information I am looking for (albeit more articles than I wanted), but I can't call the context or the category. Ideally I would like to call these all over the page(s) of the site:

{exp:stash:get_list name="featured_list" match="#^.40.$#" against="this_category" limit="1"} {exp:stash:get_list name="featured_list" match="#^.41.$#" against="this_category" limit="1"} {exp:stash:get_list name="featured_list" match="#^.42.$#" against="this_category" limit="1"} {exp:stash:get_list name="featured_list" match="#^.162.$#" against="this_category" limit="1"}

Also, am I saving anything but multiple calls in this instance? Should I be looking for a context in this case?

2

OK, finally figured it out with much tweaking and changing elements. Since the output='yes' tag spit out the correct information for all articles, it was a matter of realising the embed was being triggered and not the get_list tag. The parse order was not allowing the stash:append_list tag to fire before the stash:get_list tag. I simply put process='start' to subvert the parse order and it works perfectly.

{exp:stash:embed:featured process='start'}
    {!-- 40,41,42,162 --}
    {exp:stash:get_list name='featured_list' match="#^.*40.*$#" against="this_category" limit="1"}
      {article}
    {/exp:stash:get_list}
    {exp:stash:get_list name='featured_list' match="#^.*41.*$#" against="this_category" limit="1"}
      {article}
    {/exp:stash:get_list}
    {exp:stash:get_list name='featured_list' match="#^.*42.*$#" against="this_category" limit="1"}
      {article}
    {/exp:stash:get_list}
    {exp:stash:get_list name='featured_list' match="#^.*162.*$#" against="this_category" limit="1"}
      {article}
    {/exp:stash:get_list}

On the other note, the queries on the page went down by eight overall queries, which tells me that this is worth the effort in stashing this away. On a big site with a lot of traffic that's 8 less queries per page call that ever hit the database.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.