Created
February 24, 2011 08:52
-
-
Save ajshort/841932 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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