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, Ed, biapar, Willr, Ingo, swaiba

Can you render a specific $Layout

Go to End

2 Posts   2745 Views


Community Member, 125 Posts

5 October 2010 at 7:39am

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
that would control just the $Layout rendering and not touch the page.


Community Member, 904 Posts

5 October 2010 at 8:51am

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 as main template and Layout/ for the layout part.