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

Page Specific Templates


Go to End


2 Posts   1601 Views

Avatar
lenwood

Community Member, 18 Posts

27 March 2010 at 10:16am

Hi All,
I know that this is probably simple to accomplish but the answer is eluding me. How do I create a template that will only be applied to a couple of pages? I'd like for the site to have a couple pages with nothing but an image, no header, no logo, no navigation menu, just an image. I'm having a hard time figuring out how to accomplish this.

Thanks,
Chris

Avatar
Willr

Forum Moderator, 5523 Posts

27 March 2010 at 3:38pm

Well the easiest way is to just make new page types. So the pages which have different layouts would be a different page type to the others. Tutorial 2 covers making new page types.

If you don't want to make separate page types for the layouts you could do something like have a dropdown field on the page in the cms where the user can choose the page template.


<?php

class Page extends SiteTree {

static $db = array(
'Template' => "Enum('One, Two, Three', 'One')"
);

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Template', new DropdownField('Template', 'Template', $this->dbObject('Template')->enumValues());

return $fields;
}

That will put the template option in the cms. then in the function init() in that same file you can use $this->renderWith($this->Template) to implement a custom template. Making separate page types is easier.