This is driving me crazy...Earlier today I came across a handy variable which I can use in my Page.php etc. which gives me the path to the theme currently in use, to save having to hard code this stuff in there (always a bad idea). But for the life of me I can't find it again although I've searched through the docs for ages. Someone please put me out of my misery!
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.
Within a template you can use $ThemeDir which is where you would likely be referencing things relatively.
If you want to generate it yourself have a look at the code for the control above in ViewableData:
public function ThemeDir($subtheme = null) {
$theme = SSViewer::current_theme();
if($theme) {
return "themes/$theme" . ($subtheme ? "_$subtheme" : "");
} else {
return project();
}
}
Thanks for that. Now knowing its name, I can determine that where I read about it was here: http://doc.silverstripe.org/doku.php?id=themes:developing. Should have thought to look there, but I'm still not sure what documentation is where.
But what about referencing the theme directory on a PHP code page (as opposed to on a .ss theme page). Can $ThemeDir be used there instead of having to hardcode the reference to the chosen theme?
For example to customise the icon for a new page type:
static $icon = "themes/My_Theme_Name/images/treeicons/home";
Is there a way to use $ThemeDir here so that the theme isn't hardcoded and if the theme changes this doesn't need to be updated?
Thanks, Neil
this might work...
function init() {
parent::init();
$this->set_stat('icon',"themes/".SSViewer::current_theme()."/images/treeicons/home");
}
That's not working for me. Thanks for the speedy response though
Just out of cursorily what does "doesn't work" mean?
is the line of code called?
if not then the init function is in the wrong place...
if so does it attempt to set the static with the correct string?