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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Multiple Layouts


Go to End


4 Posts   5803 Views

Avatar
tommyoneill

Community Member, 1 Post

24 December 2008 at 3:43am

How do you create multiple layouts in one theme? Most sites I create have several layouts for different content types. How do we select different layouts?

Avatar
Liam

Community Member, 470 Posts

25 December 2008 at 6:06am

Have you read the tutorials yet? http://doc.silverstripe.com/doku.php?id=tutorials

There is a special variable called $Layout which will rendered a specific template that matches a custom page type you have created.

You can also make multiple themes and call them per page using renderwith() http://doc.silverstripe.com/doku.php?id=templates&s=renderwith#calling_templates_from_php_code

Avatar
markakl

Community Member, 3 Posts

22 October 2014 at 3:14pm

Edited: 22/10/2014 3:17pm

I've read through the tutorial and quite honestly the templating setup baffling. If you create a page and controller - say 'Home' and 'HomeController' then in 'themes/mytheme/templates/' create a HomePage under 'layouts' and a layout file called 'Home' under 'templates' the layout file is not used? Instead it continues to use the default layout?

From what I've gathered the 'HomePage' if used in the cms should inherit from all 'Home' related instances but this is not the case?

mysite/code/HomePage.php
mysite/code/Page.php
themes/simple/templates/Home.php
themes/simple/templates/Page.php
themes/simple/templates/Layout/HomePage.php
themes/simple/templates/Layout/Page.php

I can use return $this->renderWith('Home'); from the controller but this simply loads the layout without the page content, so now I have the reverse issue. What am I doing wrong here?

I realise this is an old thread but it's the top result when looking into this. I'm attempting to use version 3.1

Avatar
markakl

Community Member, 3 Posts

22 October 2014 at 3:25pm

Edited: 22/10/2014 3:27pm

Ok, for anyone else stumbling across this issue, the answer is http://www.silverstripe.org/community/forums/general-questions/show/19426#post375513

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

I still don't understand why a standard view is considered a layout. It seems the natural solution is the page 'view' references a layout.