theming - theme switching, template and css file layout on a django site -
in django site want offer several themes our best clients , boss. created following. - glad got along present there few dirty hacks want eliminate nice solutions ask for.
here's hack
base.html says (take care - ugly!)
{% ifequal theme "0" %} {% include "base_d0.html" %} {% endifequal %} {% ifequal theme "1" %} {% include "base_d1.html" %} {% endifequal %} {% ifequal theme "2" %} {% include "base_d2.html" %} {% endifequal %}
then kept in media dir subdirs common css , js
and created subdirs
static/ d0/ ( theme 0 stuff ) css/ js/ d1/ ( theme 1 stuff ) css/ js/ ... css/ (all common css) js/ (all common js)
my controller has method switch design, current 1 stored in cookie. checked on every request , in template prefix_static
context variable accordingly /mypathto/static/d0 resp. +d1 +d2
, of course had invent common_static
var. , theme var set base.html switch.
of course googled before starting found hard find search terms (as expect there many resources )
from loader_tags.py include_node do_extends doc:
this tag may used in 2 ways: ``{% extends "base" %}`` (with quotes) uses literal value "base" name of parent template extend, or ``{% extends variable %}`` uses value of ``variable`` either name of parent template extend (if evaluates string) or parent tempate itelf (if evaluates template object).
so changed templates
{% extends base %}
instead of
{% extends "base.html" %}
and set context var "base" theme + "/base.html"
in main controller before call get_template
Comments
Post a Comment