Hey,

I just discovered a pattern for allowing templates to be overridden in
Jinja2 that seems to work better than just using a ChoiceLoader. The
problem I was trying to solve is that often, the user will want to
override only a small part of a template, not the entire thing. My
solution is to do this:

system_loader = FileSystemLoader('/path/to/system/templates')
override_loader = FileSystemLoader('/path/to/override/templates')
loader = ChoiceLoader([
    PrefixLoader({'sys': system_loader}, delimiter=':'),
    override_loader,
    system_loader
])

That way, override templates can inherit from their corresponding
system templates using {% extends "sys:foo.html" %}. As long as the
system template puts blocks around everything a user might want to
override separately, this seems to work very well.

I'm just wondering whether this is a known pattern, and if there are
any downsides I haven't thought of.

Thanks,
Leif

-- 
You received this message because you are subscribed to the Google Groups 
"pocoo-libs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pocoo-libs?hl=en.

Reply via email to