html rendering - Jinja2 Dependencies During Render -
i trying build dependency graph render of template , running bit of trouble trying information out of jinja.
i want able render template , list/set of of files used render template. example:
# template.html {% extend base.html %} {% partial in partials %} {% include partial %} {% endfor %}
and have render , find out files used.
# deps.py base_path = os.path.dirname(os.path.realpath(__file__)) jinja_env = jinja2.environment( loader=jinja2.filesystemloader(base_path)) template = jinja_env.get_template('template.html') template.render({ "partials": [ "test1.html", "test2.html", ], }) # ??? looking_for = ['base.html', 'test1.html', 'test2.html']
i have checked out ast
tree , meta.find_referenced_templates(ast)
works when using constant string include path.
tried custom extension looking @ tokens, has same issues can see variable name, cannot values of variable since done during parsing/compiling phase.
also tried overriding {% include %}
wasn't sure how correctly.
by using custom loader values, if have not been loaded before since environment caches loaded templates. (this solution may work if disable caching has significant performance impact on rendering.)
how can keep track of extend/include dependencies used single template render?
Comments
Post a Comment