Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » How to change $Layout theme?

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1 2
Go to End
Author Topic: 4522 Views
  • pIscIs
    Avatar
    Community Member
    8 Posts

    How to change $Layout theme? Link to this post

    Hi all,

    i thinking how to change $Layout theme from page controller, now $Layout depends on page type and associated template with it(in Layout dir), but lets say i have two Page type pages and want that the $Layout would be rendered with different themes. How can I do that? Is it possible?

  • CodeGuerrilla
    Avatar
    Community Member
    105 Posts

    Re: How to change $Layout theme? Link to this post

    I also have a similar question I would like to swap the layout from the controller as I understand $controller::renderWith("TemplateName"); will swap the whole template, I would like to know if there is a way to keep the current template and only swap the $layout portion from the controller?

  • CodeGuerrilla
    Avatar
    Community Member
    105 Posts

    Re: How to change $Layout theme? Link to this post

    Okay figured it out $controller::renderWith(array("LayoutTemplate", "PageTemplate"));

    Basically by passing the Layout template then the Page template it will render in the correct order.

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: How to change $Layout theme? Link to this post

    So you'd want change the Layout template, without creating a new page type?

    It makes sense. We also have a ticket in our open source tracker to allow choosing of a layout template from the CMS. So, you could create templates like Page_twocols, Page_threecols, Page_wide, Page_narrow, Page_alternative or anything you'd like, and you can choose any of those templates using a dropdown on each page, which defaults to just "Page", of course.

    Here's the ticket if you want to see: http://open.silverstripe.com/ticket/2791

    Sean

  • CodeGuerrilla
    Avatar
    Community Member
    105 Posts

    Re: How to change $Layout theme? Link to this post

    Yes exactly. That sounds good Typo3 has a similar thing and sub pages will inherit their parents temple which is also useful.

  • ojalà
    Avatar
    Community Member
    87 Posts

    Re: How to change $Layout theme? Link to this post

    HI!
    I have the same problem, I don't know where is the file to modify $controller::renderWith(array("LayoutTemplate", "PageTemplate"));

    I have an othe question: if I use ticket http://open.silverstripe.com/ticket/2791 how cai I use this? I read guide but I don't understand if is possible to download thicket..

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: How to change $Layout theme? Link to this post

    Sorry, I wasn't clear.

    That's a ticket for the functionality to be added. It means that someone came up with the idea, and we just added it to the tickets for someone to create the functionality at a later date.

    Until then, you can just use the method that CodeGuerrilla has shown.

    CodeGuerrilla, did you put your renderWith() method inside the Page_Controller init() method?

  • CodeGuerrilla
    Avatar
    Community Member
    105 Posts

    Re: How to change $Layout theme? Link to this post

    No, I was calling it via another method of the controller:

    function archive()
    {
       return self::renderWith(array("NewsArchive", "Page"));
    }

    Basically will use the NewsArchive.ss layout file but will still use the main Page.ss template works well, with the exception of the Breadcrumbs

    4522 Views
Page: 1 2
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.