Jump to:

23459 Posts in 18906 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Can you render a specific $Layout

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

Page: 1
Go to End
Author Topic: 1933 Views
  • otherjohn
    Community Member
    125 Posts

    Can you render a specific $Layout Link to this post

    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.

  • banal
    Community Member
    901 Posts

    Re: Can you render a specific $Layout Link to this post

    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.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.