Jump to content

Undefined variable: template


Claus
 Share

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...