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?
I would like to avoid duplicating templates unnecessarily (e.g. every theme *has* to have all of the templates, even if there is no override) if possible. So far I see my options as either duplicating templates or writing a custom {% include %} tag that is theme-aware. Thanks, Clinton On Saturday, April 8, 2017 at 5:44:17 AM UTC-4, Russell Keith-Magee wrote: > > > On Sat, Apr 8, 2017 at 1:28 AM, Clinton Blackburn <clinton....@gmail.com > <javascript:>> 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 <javascript:>. >> To post to this group, send email to django...@googlegroups.com >> <javascript:>. >> 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 >> >> <https://groups.google.com/d/msgid/django-users/8aaf04dc-2de7-4972-8ae5-aaaefa2bf17f%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@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/56df3fa6-a4dd-4b47-904e-1c597e6321d0%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.