Last Updated: February 25, 2016
·
705
· apug

Create a fully themeable symfony1 application

If you want create a fully themeable application with Symfony1
with a great separation between logic and graphic edit your application
configuration class, e.g. frontendConfiguration.class.php
and add this methods.

public function getTemplateDirs($moduleName) {
    $dirs = parent::getTemplateDirs($moduleName);
    $appName = $this->getApplication();
    $template = sfConfig::get('sf_root_dir') . DIRECTORY_SEPARATOR .'themes' . DIRECTORY_SEPARATOR . sfConfig::get('app_theme_name', 'default') . DIRECTORY_SEPARATOR . 'apps/' . $appname . '/modules/' . $moduleName . '/templates';

    return array_unshift($dirs,$template);
}

public function getDecoratorDirs() {
      $dirs = parent::getDecoratorDirs();
       $appname = $this->getApplication();
       $decorator = sfConfig::get('sf_root_dir') . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . sfConfig::get('app_theme_name', 'default') . DIRECTORY_SEPARATOR . 'apps/' . $appname . '/templates';
        return array_unshift($dirs,$decorator);
}

Now you can create your templates and layouts inside your theme folder following the same rules of symfony:
For example, if your theme name is MyTheme
create layouts in /themes/MyTheme/apps/frontend/templates and
templates in /themes/MyTheme/apps/frontend/modules/[MODULENAME]/templates