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.

Archive /

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

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

How to change $Layout theme?


Go to End
Reply


10 Posts   4640 Views

Avatar
pIscIs

Community Member, 8 Posts

15 May 2008 at 6:15pm

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?

Avatar
CodeGuerrilla

Community Member, 105 Posts

8 October 2008 at 5:16pm

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?

Avatar
CodeGuerrilla

Community Member, 105 Posts

8 October 2008 at 6:08pm

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.

Avatar
Sean

Forum Moderator, 922 Posts

8 October 2008 at 8:01pm

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: [url]http://open.silverstripe.com/ticket/2791[/url]

Sean

Avatar
CodeGuerrilla

Community Member, 105 Posts

8 October 2008 at 8:20pm

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

Avatar
ojalà

Community Member, 87 Posts

9 October 2008 at 2:10am

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..

Avatar
Sean

Forum Moderator, 922 Posts

9 October 2008 at 8:39am

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?

Avatar
CodeGuerrilla

Community Member, 105 Posts

9 October 2008 at 12:29pm

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 :)

Go to Top