On Sat, Apr 8, 2017 at 1:28 AM, Clinton Blackburn <
clinton.blackb...@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+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/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/CAJxq84-T8hYB5NrC0PY9%3D_J6nw%2BY57cK-Zrt5Qj-Qz5C%3DQggag%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to