I have a website with more or less a thousand news items in a channel and was wondering what was the best way to handle this with stash if I want to separate the logic from the HTML code as much as possible.
1. Using set_list / get_list
Wrapping your channel:entries
tags in a set_list
then using get_list
and stash pagination does not look like it is the right approach since getting 1000 items with a channel entry loop is going to be very time consuming. What's nice is that you can cache the list and not hit the channel entries tags on subsequent visits.
2. Using append_list / get_list
The approach I currently favor is to use channel:entries
tags on the outside and using an append_list
tag pair on the inside and stashing the pagination works fine. But there, we hit the channel:entries
tags on every page load and I don't see how stash caching could be useful in that context.
{!-- Build news list --}
{exp:channel:entries disable="categories|category_fields|member_data|trackbacks" channel="news" status="open" orderby="date" sort="desc" limit="10" paginate="bottom"}
{exp:stash:append_list name="st_news"}
{stash:st_title}{title}{/stash:st_title}
{stash:st_date}{entry_date format="%F %d, %Y"}{/stash:st_date}
{stash:st_machinedate}{entry_date format="%Y-%m-%d"}{/stash:st_machinedate}
{stash:st_url}{url_title_path="news_press/news"}{/stash:st_url}
{stash:st_image}{cf_news_img}{/stash:st_image}
{stash:st_summary}{exp:eehive_hacksaw words="30" append="..."}{cf_news_summary}{/exp:eehive_hacksaw}{/stash:st_summary}
{/exp:stash:append_list}
{paginate}
{exp:stash:set name="st_pagination" parse_tags="yes"}
{pagination_links}
<ul class="pagination group">
{first_page}<li><a href="{pagination_url}">First</a></li>{/first_page}
{page}<li><a href="{pagination_url}"{if current_page} class="current"{/if}>{pagination_page_number}</a></li>{/page}
{last_page}<li><a href="{pagination_url}">Last</a></li>{/last_page}
</ul>
{/pagination_links}
{/exp:stash:set}
{/paginate}
{/exp:channel:entries}
and then in a snippet or in the same template
{exp:stash:get_list name="st_news" prefix="stashprefix"}
{if count == "1"}<ul class="horizimglist">{/if}
<li class="group">
<p class="imgholder"><a href="{st_url}">{exp:ce_img:pair src="{st_image}" width="680" height="382" crop="yes|center, center" allow_scale_larger="yes"}<img src="{made}" alt="{title}" />{/exp:ce_img:pair}</a></p>
<div class="postcontent">
<p class="info"><time datetime="{st_machinedate}" pubdate="pubdate">{st_date}</time></p>
<h2><a href="{st_url}">{st_title}</a></h2>
<p>{st_summary}</p>
</div>
</li>
{if count == total_results}</ul>{/if}
{!-- if no results --}
{if stashprefix:no_results}<p>No News Found</p>{/if}
{!-- Pagination --}
{if count == total_results}{exp:stash:get name="st_pagination"}{/if}
{/exp:stash:get_list}
I was just curious to know:
- what is the approach stash experts use in such a context
- are there stash options/parameters (save/refresh/replace) I could use to have better performance