Skip to content

Instantly share code, notes, and snippets.

@ajshort
Created February 24, 2011 08:52
Show Gist options
  • Select an option

  • Save ajshort/841932 to your computer and use it in GitHub Desktop.

Select an option

Save ajshort/841932 to your computer and use it in GitHub Desktop.
<?php
/**
* Adds the ability to select a theme to use to render a page, and have it
* cascade down the tree.
*/
class Page extends SiteTree {
public static $db = array(
'Theme' => 'Varchar'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$theme = new DropdownField(
'Theme',
null,
SiteConfig::current_site_config()->getAvailableThemes(),
null, null,
'(Inherit from parent)');
$fields->addFieldToTab('Root.Behaviour', $theme, 'ParentType');
return $fields;
}
}
class Page_Controller extends ContentController {
public function init() {
parent::init();
$current = $this;
while ($current && !$current->Theme) {
$current = $current->ParentID ? $current->Parent() : false;
}
if ($current) {
SSViewer::set_theme($current->Theme);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment