-
Symfony: selectively replacing application templates with a plugin
Posted on February 15th, 2009 3 commentsAfter many headaches about how the hell I can get symfony to look for a layout or a template in a plugin directory first, so that you can selectively replace default layouts (meaning the ones in the application or module template directory) with versions provided by a specific plugin, I figured out a simple and yet elegant solution. It actually took me a few hours of crawling through symfony code to figure out that it all boils down to the application configuration.
Solution: Simply overwrite the directoy getter in the Configuration class of your application and insert your disired location at the front of the array.
class MyExampleApplicationConfiguration extends sfApplicationConfiguration
{
[..]
public function getTemplateDirs($moduleName)
{
$dirs = parent::getTemplateDirs($moduleName);
array_unshift($dirs,sfConfig::get('sf_plugins_dir').'/SomePlugin/apps/'.$this->getApplication().'/modules/'.$moduleName.'/templates');
return $dirs;
}
[...]
}
Do the same thing with getDecoratorDirs() to replace layout files. It even works for I18n, because they too use a function in sfApplicationConfiguration to get their candidate directories.


