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: http://www.symfony-project.org/snippets/snippet/115 (btw, there is also the other one which explains some other aspects of this stuff: http://www.symfony-framework.com/2008/05/22/themes-management-system-with-symfony-step-by-step-tutorial/).
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()
{
parent::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()))
{
$this->setDirectory($this->getDirectory().'/'.$theme);
}
// Look for a layout in a $theme/ subdirectory of the usual layout location
if (is_readable($this->getDecoratorDirectory().'/'.$theme.'/'.$this->getDecoratorTemplate()))
{
$this->setDecoratorDirectory($this->getDecoratorDirectory().'/'.$theme);
}
}
}
}
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.
2 replies on “Time to change skin”
[…] Time to change skin […]
just to say, I found this really useful
only took a couple of hours to go from this.
http://www.savewatersavemoney.co.uk
to this..
http://awdirect.savewatersavemoney.co.uk
http://wessexwater.savewatersavemoney.co.uk
and a few more varations – all running the same code but with url dependant templates.