Sep 07

Time to change skin

Hi everyone,

So about skins.. This short note is for those who wants to allow customizing of their project with themes. It’s really easier than you can thought. As a basic manual we’d recommend this snippet: (btw, there is also the other one which explains some other aspects of this stuff:

So main idea is you can use the same layout template and customize it based on defined theme.
They recommend to use the following view class to allow themes functionality:

class myView extends sfPHPView
public function configure()

// Grab the theme from the user (of from anywhere else)
$theme = $this->getContext()->getUser()->getTheme();

// If there is a theme and if the theme feature is enabled
if($theme && sfConfig::get('app_theme'))
// Look for templates in a $theme/ subdirectory of the usual template location
if (is_readable($this->getDirectory().'/'.$theme.'/'.$this->getTemplate()))

// Look for a layout in a $theme/ subdirectory of the usual layout location
if (is_readable($this->getDecoratorDirectory().'/'.$theme.'/'.$this->getDecoratorTemplate()))


Well, if you still use symfony 1.0 this can be also good way to allow visitors to see your site in different formats (i.e. you can use themes to show content in different formats just via overriding main theme or layout). symfony 1.1 supports another way to allow accessing site in different formats so there is no need in such class.

Author: symfonian


[…] Time to change skin […]

December 4, 2008

just to say, I found this really useful

only took a couple of hours to go from this.

to this..

and a few more varations – all running the same code but with url dependant templates.

Comments RSS TrackBack Identifier URI

Leave a comment