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

Partial Caching - How do you make a cache for different children


Go to End


4 Posts   1054 Views

Avatar
john_0312

Community Member, 2 Posts

13 March 2012 at 12:27am

Hey there!

I need some help in using the partial caching feature. When I put a cache on the main <% control Children %>, it shows the same page for all of the other children.

For example, I have a /products/bangles/ section on the website rendered by a ProductsCategory.ss template. When I access /products/earrings/, the products for bangles show up as well. That goes true for all the other siblings of the categories.

My main question is, is there a way to enable partial caching for all of the children of products and cache them all separately?

Thanks in advance for your help!

Avatar
dpde

Community Member, 15 Posts

13 March 2012 at 1:11am

Edited: 13/03/2012 1:14am

Of course.
You have to give them different cache keys

for example:

<% control Products %>
<% cached %>
$ProductName
<% end_cached %>
<% end_control %>

wont work, try the following:

<% control Products %>
<% cached 'Product', ID %>
$ProductName
<% end_cached %>
<% end_control %>

Avatar
john_0312

Community Member, 2 Posts

13 March 2012 at 1:40am

Hi dpde!

Thank you so so very much for your prompt response. It worked brilliantly!

I really appreciate the help that you have given me. :)

Till next time!

Avatar
dpde

Community Member, 15 Posts

13 March 2012 at 1:53am

You are welcome. ;)

More information about partial caching can be found here:
http://doc.silverstripe.org/sapphire/en/reference/partial-caching