Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

[SOLVED] Partial Cache of Pagianted List


Go to End


3 Posts   1484 Views

Avatar
zenmonkey

Community Member, 545 Posts

17 March 2015 at 7:15am

I'm trying to cache the pages of a paginated list but my cache block seems to be returning the first page:

<% cached 'OtherArtists-{$OtherArtists.CurrentPage}', $List('Artist').max('LastEdited') %>
<% if $OtherArtists %>
	<h2>Works Available By 
		<% if $OtherArtists.MoreThanOnePage && $OtherArtists.NotFirstPage %>
		 <small class="page-count">Page $OtherArtists.CurrentPage of $OtherArtists.TotalPages</small>
		<% end_if %>
	</h2>
	<ul class="artwork-grid" id="Posts">
		<% loop $OtherArtists %>
			//Code
		<% end_loop %>
	</ul>
<% end_if %>
<% end_cached %>

Avatar
wmk

Community Member, 87 Posts

17 March 2015 at 7:46am

Edited: 17/03/2015 7:47am

Hi, afaik you can add as much keys to

<% cached %>
as you like, so I'd try

<% cached 'OtherArtists',  $OtherArtists.CurrentPage, $List('Artist').max('LastEdited') %>

See Partial Caching Docs

Avatar
zenmonkey

Community Member, 545 Posts

18 March 2015 at 3:31am

I ended up generating the cache key though the controller instead of the template, that I was I was able to ensure the offset gets used