Claus Posted November 16, 2014 Share Posted November 16, 2014 I’m trying to use the $template->name by declaring this in "_init.php": $cssFile = $template->name . ".css"; … and I then have this in "_main.php": // Use custom CSS-file if that file exists. <?php if(is_file($config->paths->templates . "styles/$cssFile")) { echo "<link rel='stylesheet' type='text/css' href='{$config->urls->templates}styles/$cssFile' />"; }; ?> However PW throws this notice: Notice: Undefined variable: template in /Users/claus/Sites/ProcessWire/site/templates/_init.php on line 29 Notice: Trying to get property of non-object in /Users/claus/Sites/ProcessWire/site/templates/_init.php on line 29 // Use custom CSS-file if that file exists. Do I have to define $template->name? I thought that was a built-in function? Link to comment Share on other sites More sharing options...
SiNNuT Posted November 16, 2014 Share Posted November 16, 2014 I'm not sure but what happens if you set $cssFile in _main.php? _init.php runs before any template files, and maybe $template->name is not yet available? Link to comment Share on other sites More sharing options...
Claus Posted November 16, 2014 Author Share Posted November 16, 2014 I'm not sure but what happens if you set $cssFile in _main.php? _init.php runs before any template files, and maybe $template->name is not yet available? That was also what I was thinking, but PW gives me the same error: Undefined variable: template … if I put it in _main.php. I’m quite puzzled by this one. Link to comment Share on other sites More sharing options...
Fokke Posted November 16, 2014 Share Posted November 16, 2014 Hi! Try using $page->template->name instead. 1 Link to comment Share on other sites More sharing options...
Claus Posted November 16, 2014 Author Share Posted November 16, 2014 Bingo! Being the n00b that I am I had not considered that possibility Thanks fokke! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now