18591 Posts in 4875 Topics by 2285 members
General Questions
SilverStripe Forums » General Questions » Referencing theme files in PHP files
General questions about getting started with SilverStripe that don't fit in any of the categories above.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba
|
Page:
1
|
Go to End | |
| Author | Topic: | 711 Views |
-
Referencing theme files in PHP files

27 August 2009 at 1:02am
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!
-
Re: Referencing theme files in PHP files

27 August 2009 at 9:20am Last edited: 27 August 2009 9:21am
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();
}
} -
Re: Referencing theme files in PHP files

27 August 2009 at 9:58am
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.
-
Re: Referencing theme files in PHP files

24 May 2011 at 1:28am
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 -
Re: Referencing theme files in PHP files

24 May 2011 at 1:54am
this might work...
function init() {
parent::init();
$this->set_stat('icon',"themes/".SSViewer::current_theme()."/images/treeicons/home");
} -
Re: Referencing theme files in PHP files

24 May 2011 at 2:34am
That's not working for me. Thanks for the speedy response though
-
Re: Referencing theme files in PHP files

24 May 2011 at 2:41am
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?
| 711 Views | ||
|
Page:
1
|
Go to Top |




