Base-Templates Dir Feature Added to Smarty 1.4.0
| From: | Mirko Buffoni | Date: | Thu, 10 May 2001 09:39:49 +0000 |
| Subject: | Base-Templates Dir Feature Added to Smarty 1.4.0 | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-712@lists.php.net to get a copy of this message | ||
Hi folks,
I did a small modification to the current Smarty source, in order to
achieve a behavior similar to basic-class -> extented-class paradigm,
that is to have a set of templates so called 'Basic', general-purpose,
in a common directory. If a template is found in the $template_dir,
it will override the general one, otherwise, smarty will check for the
presence of template in the common repository directory, if not it will
issue an error.
I know I could have done this by registering a special function. I'll just
wait for a comment from Monte or Andrei, to see if this change can fit in the
code. Note that this change won't influece normal compiled templates dir,
which will still hold the compiled templates as if they were taken from the
template_dir. The same apply to cached md5 encoded names.
Also, is there any way to set up a variable by default every time a smarty
class is declared, call it PHP_SELF, that contains the name of the file
currently requesting template interpretation? Or can I access $PHP_SELF
variable from template, without forcing SMARTY_PHP_ALLOW in the code?
Mirko Buffoni
============
class Smarty
{
// public vars
var $template_dir = './templates'; // name of directory for templates
// MB 10052001
var $template_base = './templates'; // if a template is not found in $template_dir,
// it will try this one (for basic templ. def.)
...
---
in _fetch_template_source method:
switch ($resource_type) {
case 'file':
if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/",$resource_name)) {
// relative pathname to $template_dir
// MB 10052001
$resource_name_base = $this->template_base.'/'.$resource_name;
$resource_name = $this->template_dir.'/'.$resource_name;
}
if (file_exists($resource_name)) {
$template_source = $this->_read_file($resource_name);
$template_timestamp = filemtime($resource_name);
return true;
// MB 10052001
} else if (file_exists($resource_name_base)) {
$template_source = $this->_read_file($resource_name_base);
$template_timestamp = filemtime($resource_name_base);
return true;
} else {
$this->_trigger_error_msg("unable to read template resource: \"$tpl_path\"");
return false;
}
break;
================================================================
"If you want something about your program to be never discovered
by anybody, just write it in the docs." (1st MAME law)================================================================