Has anyone solved site-aware theming? I have a multi-tenant site (using sites framework) and I want to render custom templates for each site. My current design calls for a default design, and overrides of the base template (or child templates) for each site. Obviously, I can achieve the overrides by prepending the site/theme name when I include a template/static file. However, this does not allow for easy support of a default fall-back.
How have others solved this problem? Are you using thread.local/global variables, as I've seen in some locations?Are there any plans to support a request/site-aware template loader?Thanks,Clinton
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8aaf04dc-2de7-4972-8ae5-aaaefa2bf17f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On Sat, Apr 8, 2017 at 1:28 AM, Clinton Blackburn <clinton....@gmail.com> wrote:Has anyone solved site-aware theming? I have a multi-tenant site (using sites framework) and I want to render custom templates for each site. My current design calls for a default design, and overrides of the base template (or child templates) for each site. Obviously, I can achieve the overrides by prepending the site/theme name when I include a template/static file. However, this does not allow for easy support of a default fall-back.Actually - it does.Any time you specify a template to render, you can also specify a *list* of templates. So, you can do something like this:def my_view(request):…return render(request, [‘path/to/template/%s/template.html’ % user_theme,‘path/to/template/default/template.html’,], {…context…})That will pick the user’s theme by default; if the user’s theme doesn’t specify a given template, or the user doesn’t have a theme (or the user’s theme is set to default), it will use the default theme directory.Hope that helps!Yours,Russ Magee %-)
How have others solved this problem? Are you using thread.local/global variables, as I've seen in some locations?Are there any plans to support a request/site-aware template loader?Thanks,Clinton
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
Russ,How would this work for base/nested templates? Say my view is rendering the potential templates ['my-theme/page.html', 'page.html'], and the templates inherits base.html. Do I have to override base.html for every theme if I want base.html (or any other child/parent template) to be theme-able? Is there a version of {%include%} that takes an array, or will I need to write my own tag?