5095 Posts in 1518 Topics by 1114 members
| Go to End | Next > | |
| Author | Topic: | 3643 Views |
-
allow user to customize page theme

17 January 2009 at 11:31am
I'm by no means any sort of expert when it come to coding or php but I am trying to implement a drop down box in the cms on Root.content.main that will allow the user to set the theme for the page.
I could but completely off but this is the code I have come up with so far... as now I getting a parse error on line "SSViewer::set_theme('$Theme');"
---------------------------
<?phpclass Page extends SiteTree {
static $db = array(
'Theme' => "Enum('higherground,blackcandy','higherground')"
);static $has_one = array(
);function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new DropdownField(
'Theme',
'Select A Theme:',
singleton('Page')->dbObject('Theme')->enumValues()
));
return $fields;}
}class Page_Controller extends ContentController {
function init() {
switch($this->URLSegment) {
SSViewer::set_theme('$Theme');
break;
}parent::init();
Requirements::themedCSS("layout");
Requirements::themedCSS("typography");
Requirements::themedCSS("form");}
}
?>
P.S. LOVE SilveStripe!!!
-
Re: allow user to customize page theme

17 January 2009 at 11:44am
Change:
SSViewer::set_theme('$Theme');
to:
SSViewer::set_theme("$Theme");
A string encapsulated in single quote marks will not evaluation php variables, so your script was trying to set it to a theme called $Theme
-
Re: allow user to customize page theme

17 January 2009 at 12:06pm
I tried what you suggested and I still got a parse error on the same line. Just for kicks I ran the code below and it worked as anticipated. Which would lead me to believe it is definitely in the commented function... but I don't have any idea how to fix it...
<?php
class Page extends SiteTree {
static $db = array(
'Theme' => "Enum('higherground,blackcandy','higherground')"
);static $has_one = array(
);function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new DropdownField(
'Theme',
'Select A Theme:',
singleton('Page')->dbObject('Theme')->enumValues()
));if (!Permission::check("ADMIN")){
$fields->removeFieldFromTab('Root','Access');
}
return $fields;}
}class Page_Controller extends ContentController {
function init() {
/*switch($this->URLSegment) {
SSViewer::set_theme("$Theme");
break;
}*/parent::init();
Requirements::themedCSS("layout");
Requirements::themedCSS("typography");
Requirements::themedCSS("form");}
}
?>
-
Re: allow user to customize page theme

19 January 2009 at 7:37am
Maybe I'm missing something, but why even put quotes around $Theme?
SSViewer::set_theme($Theme); should work as well.
Also,
why have a switch when you don't have 'cases'?
Just leave the switch out I would think. If $theme is set per page it will automatically set this, no switch $urlsegment needed...
-
Re: allow user to customize page theme

19 January 2009 at 1:00pm
Tried what you suggested with no luck... I tried it with no quot, single quote, double quotes, with and without the swith $URLsegment... nothing
I also tried removing the theme call in the _config file but that did not help
I was able to build and seemingly select the theme in the CMS but the pages would not render stating an error in SSVeiwer.php on line 151
-
Re: allow user to customize page theme

19 January 2009 at 1:51pm
Hey there,
remove the switch statement, all you need is to put "SSViewer::set_theme($this->Theme);" where you have the commented out switch.
-
Re: allow user to customize page theme

20 January 2009 at 10:25am
Tried what you suggested and I am still getting errors. Again the build is going well but when the page tries to render i get errors... I also see the same errors if I try to access the admin page ... The error is saying that it can not find the template Page.ss... Almost seems like it is looking for the for the .ss files before the theme is set??
-
Re: allow user to customize page theme

20 January 2009 at 10:36am
Could you check a few things:
- try a flush first (add ?flush=1 to your url)
- check if there's really a value saved in the database?
- do a Debug::show($Theme); right before SSViewer::set_theme... to see what the value is.Perhaps this call to set the theme is indeed too late and should happen earlier?
| 3643 Views | ||
| Go to Top | Next > |




