Every time a tpl file is included the system first looks for a site-specific version of the file and falls back to a standard one if the site specific one does not exist. So perahps I put include “customer/main/test1.tpl”. If our site is google, the system would first look for “customer/main/google_test1.tpl” and fall back to “customer/main/test1.tpl” if that file doesn’t exist.
Note: Smarty 2.6.x
Did you know about the built-in template directory cascade? addTemplateDir and setTemplateDir allow you to specify multiple directories:
Smarty will first try to find
my-templates/google/foobar.tpl, if not found trymy-templates/default/foobar.tpl. Using this, you can build a complete templating cascade.That won’t be too helpful if you have lots of elements on the same cascade-level. Say you had specific templates for google, yahoo and bing besides your default.tpl. A solution could involve the default template handler function. Whenever Smarty comes across a template it can’t find, this callback is executed as a measure of last resort. It allows you to specify a template file (or template resource) to use as a fallback.
So you could {include}, {extend}, ->fetch(), ->display()
site_google.tpl. If the file exists, everything is fine. If it doesn’t, your callback could replace_googlewith_defaultto fallback to the default template.If neither template_dir cascade nor default template handler function seems applicable, you’ll want to dig into custom template resources.