John Trash John Trash - 1 year ago 137
Smarty Question

smarty - filter template paths before they get loaded

I am writing a plugin for a quite complex project realized with Smarty2 (pretty oldscool, yes, it's not my decision). I have to change some templates, but only two or three of hundreds (for example the one which generates the page's navbar). Problem is:
- they dont't have any hooks or variables where I would need some
- I cannot modify them (because I want to keep the whole thing updateable)
But I have access to the $smarty object and can use it's methods such as assign.

Is it somehow possible to filter the template-urls before they get displayed? I have something in my mind like

$smarty->replaceUrl('templates/navbar.tpl', 'myplugin/mynavbar.tpl');

Or do one of you have any other suggestion how I could solve this? I know that I could use register_outputfilter and insert my code with some string manipulation, but that would be obviously a terrible solution.

Answer Source

I found a quite convincing solution by myself

array_unshift($smarty->template_dir, $myTemplatePath);

In my $myTemplatePath I hold my versions of every template I want to replace. Case solved.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download