Reputation: 33
I'm a newbie in SilverStripe. I need to create a new page by extending a new class sitetree. My question is how to retrieve in the template something like $Layou which is used in the classic page.php. For example, in my template folder I would like to have a folder like "Layout" organized for new pages created from this.
this is the controller:
class WhitePage extends SiteTree {
private static $db = array(
);
private static $has_one = array(
);
}
class WhitePage_Controller extends ContentController {
private static $allowed_actions = array(
);
public function init() {
parent::init();
}
function index() {
return $this->renderWith("WhitePage");
}
}
i would like in the template directory create a folder name "whitepage" within the ".ss" file, and in the template use something like $whitepage instate of $Layout ...
How to do this?
thk, a lot Francesco
Upvotes: 1
Views: 506
Reputation: 15794
You can use the master WhitePage.ss template with several page types by extending your WhitePage
class. Then you can use the $Layout
as normal to call your custom layout template.
WhitePage
class WhitePage extends SiteTree {
}
class WhitePage_Controller extends ContentController {
private static $allowed_actions = array(
);
public function init() {
parent::init();
}
}
CustomWhitePage
class CustomWhitePage extends WhitePage {
}
class CustomWhitePage_Controller extends WhitePage_Controller {
private static $allowed_actions = array(
);
public function init() {
parent::init();
}
}
In your themes/mytheme folder or mysite folder create your templates like so:
templates/Page.ss
templates/WhitePage.ss
templates/Layout/Page.ss
templates/Layout/WhitePage.ss
templates/Layout/CustomWhitePage.ss
Your Layout/WhitePage.ss
and Layout/CustomWhitePage.ss
will use the templates/WhitePage.ss
parent template while any page that extends Page
will use templates/Page.ss
.
Make sure you call ?flush=all
for your templates to be loaded the first time through.
Upvotes: 1