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

SOLVED - create a template page that does not extend any other


Go to End


3 Posts   889 Views

Avatar
wake2010

Community Member, 9 Posts

10 January 2012 at 1:25am

Hey, i am trying to make the main hope page tutorial not extend page as i am creating its own CSS and i have hit a snag

first, how do you make a the MainHomePage not be an extention of page.
seccond, how do you add a unique CSS to one page?
thanks for any help
=]

Avatar
copernican

Community Member, 189 Posts

10 January 2012 at 2:12am

Edited: 10/01/2012 2:16am

instead of extending Page extend SiteTree

class MainHomePage extends SiteTree {

}

class MainHomePage_Controller extends ContentController {

}

that should work. If the only reason you want to do this is to have custom CSS on your homepage, you can still extend Page and have different CSS for MainHomePage.

instead of putting your MainHomePage.ss template in /templates/layout, put MainHomePage.ss in your /templates folder and then use <% require themedCSS() %> to include the css files you want.

Another way to include CSS is through the use of Requirements in your init() function

class MainHomePage_Controller extends Page_Controller {

       public function init() {
		parent::init();

		Requirements::CSS('themes/'. SSViewer::current_theme() .'/css/file.css');
	}


}

Avatar
wake2010

Community Member, 9 Posts

10 January 2012 at 2:52am

thanks worked!