Very Simple Theming in Pylons

For a while I've been thinking about how to achieve themes in some of my Pylons applications, and just today I was looking around in my environment.py file, and saw the configuration of the templates and public directories. That gave me an idea, can I load a theme directory from the configuration file and use it in there?

I had a bit of a false start initially, I thought that I could just use the config object as I do elsewhere in my application, but that didn't want to work. Eventually I found the solution: the app_conf object.

This is how my code now looks:

  1. ...
  2. theme_dir = os.path.join(app_conf['themes.directory'], app_conf['themes.current'])
  3. paths = dict(root=root,
  4. controllers=os.path.join(root, 'controllers'),
  5. static_files=os.path.join(theme_dir, 'public'),
  6. templates=[os.path.join(theme_dir, 'templates')]
  7. )
  8. ...

And the relevant lines in my config.ini file:

  1. themes.directory = %(here)s/themes
  2. themes.current = default

Each theme is simply a directory with two subdirectories, "public" where my images, styles and scripts live, and "templates" where my template files live.

I'm still looking into how I can pull the current theme from the database at this early stage of the application, but this is a start in the right direction.

Hopefully, this will help someone else. If you have any suggestions for a better or more elegant solution, I'd be keen to hear about it.

Comments

jonloton0098:

I did not think so and finillay i found that really it is very simple. Thanks.

 

<a href="http://www.equines4us.com/Horses/">horses for sale</a>