Can I get Smarty to select a template from a directory based on priority?

I am creating a PHP wiki engine that uses the same template for all sites that point to it. However, some websites have their own template. Can I get Smarty to use this custom template if it exists?

Here is my directory structure:

/web/wiki/templates <-- all templates here /web/wiki/templates/wiki.domain.com <-- individual template 

How can I use templates to use smarty in /web/wiki/templates/wiki.domain.com first for wiki.domain.com , and if the template does not exist in this directory, use the template in /web/wiki/templates ?

Can I identify several template directories for Smarty and try to select a template from the top directory first? If I could do this, I could simply reorder the template directories:

 /web/wiki/templates/wiki.domain.com /web/wiki/templates 
+4
source share
4 answers

default_template_handler is a callback that is called if a template is not found. Some "examples" can be found in unit test

+1
source

From Smarty Docs , try:

 // set multiple directoríes where templates are stored $smarty->setTemplateDir(array( 'one' => './templates', 'two' => './templates_2', 'three' => './templates_3', )); 
+1
source

I don’t think you can set priority for different templates, but I’m not sure. You can check if a specific template exists:

 // check for if a special template exists $template = 'default.tpl.php'; if ($smarty->template_exists('example.tpl.php')) { $template = 'example.tpl.php'; } // render the template $smarty->display($template); 
0
source

To extend the Christer code if you have many possible patterns:

 $possibleTemplates = array( // ... ); do { $template = array_shift($possibleTemplates); } while($template && !$smarty->template_exists($template)); if(!$template) { // Handle error } $smarty->display($template); 
0
source

All Articles