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

Can you render a specific $Layout


Reply

2 Posts   1960 Views

Avatar
otherjohn

5 October 2010 at 7:39am Community Member, 125 Posts

Hi,
Is there a way I can control what template is rendered in the $Layout field. I know you can create a pagetype but I was wondering if I could do something like
$this->renderWith("page-content-right");
that would control just the $Layout rendering and not touch the page.

Avatar
banal

5 October 2010 at 8:51am Community Member, 901 Posts

Yes you can!
You can pass in an array to the renderWith method where you define templates from specific to unspecific...
An example:

$this->renderWith(array('MySpecialTemplate', 'Page'));

This will first look for a template named MySpecialTemplate. If that isn't found, the Page template will be used. This is true for both the main template as well as for the template used for $Layout.
So if you just have a layout named MySpecialTemplate, but no main template, this works equally well. It will render using Page.ss as main template and Layout/MySpecialTemplate.ss for the layout part.