Referenced templates from a template

11 views
Skip to first unread message

J Lorieau

unread,
Jul 4, 2018, 8:30:41 AM7/4/18
to pocoo-libs
Dear Pocoo team,

I would like to get a list of all parent template paths for a template loaded from a file system that includes parent (inherited) templates. I am using the standard approach described in the documentation by preparing loaders and an environment to generate a template object, which I then use to render the final string. The source includes a "find_referenced_templates" in the Meta submodule to do exactly what I'm seeking from an AST, but I could not find a way to generate an AST from an environment.Template object.

How would I go about getting a list of parent templates for a loaded template from the environment?

I've also posted this question on SO with a slightly more detailed explanation (https://stackoverflow.com/questions/51157457/jinja2-reference-templates-for-a-template). 

As a feature request, I suggest adding a 'parent_filenames' attribute to the environment.Template object to get a list of all parent template filenames. This would be a useful complementary to the 'filename' attribute of the template object. Alternative (or additionally), a 'get_ast' method in the environment.Template object would be helpful as well.

Thank you,

Justin
Reply all
Reply to author
Forward
0 new messages