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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Partial Caching


Reply


5 Posts   584 Views

Avatar
vxd

Community Member, 16 Posts

15 May 2012 at 4:29pm

Edited: 15/05/2012 5:03pm

I am using partial caching for the main content block of main template.

This is what I have in the template file

<% cached 'database', LastEdited %>
$Content
<% end_cached %>

The main template is used on most of the page.

If I visit "about us" it will display the content for about us, then when I visit "Services" it will display the content from the "about us" page

It's cached the content from "About Us" and displaying the "About Us" content on all of the pages sharing the same template.

How do I get this to work properly so it displays the content of it's own page

Thanks

Avatar
vwd

Community Member, 160 Posts

20 May 2012 at 12:46am

Hi VXD,

Try adding 'URLSegment' to the cache key. Ie.

<% cached 'database', LastEdited, URLSegment %>
   $Content
<% end_cached %>

There is an explanation of this in the [url=http://www.packtpub.com/article/silverstripe-2-4-adding-spice-with-widgets-short-codes]article on SilverStripe by Phillip Krenn[/url].

Hope this helps.

VWD.

Avatar
Willr

Forum Moderator, 5513 Posts

20 May 2012 at 11:43am

ID might be a safer key than URLSegment as you'll have multiple pages with the same URLSegment (nested urls).

Avatar
vwd

Community Member, 160 Posts

21 May 2012 at 7:23am

Hi Will,

Thanks for that suggestion - so $URLSegment is not unique across a site, and obviously $ID is.

Kind regards,
Prem.

Avatar
vxd

Community Member, 16 Posts

12 June 2012 at 12:19am

Thanks for that, so it should be

<% cached 'database', LastEdited, ID %>
$Content
<% end_cached %>