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] Using content from parent page and duplicating it across child and grandchild pages without additional fields (across different templates).


Go to End


1604 Views

Avatar
eightythree

Community Member, 12 Posts

16 April 2016 at 8:33pm

Edited: 17/04/2016 9:49pm

Hi there,
I have problem with using content from parent page in child pages (two different templates).

My site tree looks like this:

Page_1 (Template_1.ss)
--- Page_2 (Template_2.ss)
------- Page_3 (Template_3.ss)
------- Page_4 (Template_3.ss)
------- Page_5 (Template_3.ss)

It is possible to use content from Page_1 and replicate it across all child and grandchild pages (2, 3, 4, 5 etc.) without using fields in those child/grandchild pages in CMS? I’ve tried renderWith method but I don’t know how to use it properly. Is anyone used something like this and could provide some clues or snippet?

UPDATE:

It's preety easy actually. In 1st template you could declare custom fields with some content and then in child templates:

<div>
   <h2>$Parent.MyStuff</h2>
   <p>$Parent.MyStuffAlso</p>
</div>

or with include:

<% with Parent %>
   <% include SomeStuff %>
<% end_with %>

Documentation link:
https://docs.silverstripe.org/en/3.3/developer_guides/templates/common_variables/#parent

Cheers,
Darek.