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