Hi,

I was wondering if there is any hook for a jinja2 extension to run some 
code after the entire render process is done. I would need to have access 
to the final output of the render call, and to the jinja2 environment.

Background:

I'm developing a jinja2 extension for managing dependencies. The core 
concept is a new {% require %} tag that takes a path and works similarly to 
the {% include %} tag but with two key differences:

1) Each piece of content that is added this way is guaranteed to only be 
output once in the final page output.

2) Each piece of content that is added this way will be output at an 
appropriate point in the final output, regardless of where it was 
referenced from (e.g. CSS content will be in a <style> tag in the <head>, 
JavaScript will be in a <script> tag at the end of the <body>, etc.). The 
content will be ordered such that if A requires B, then B will be before A 
in the final output (so that, for example, A could override CSS rules 
defined by B).

My approach is to keep track of all of the referenced content in a 
dictionary in the environment, and then once rendering the page is done to 
insert it into the appropriate parts of the document (CSS in a <style> tag, 
etc.) via a simple string substitution. It feels pretty inelegant so I'd 
love to hear about better options! The way I'm doing that right now is by 
manually calling a method on my extension once rendering is complete to 
perform the string substitution and clear my extension's context from the 
environment. It works, but it's ugly.

Thanks for any help -- especially if it's of the form "you're approaching 
this totally wrong, here's the elegant way of solving this problem."

Best,
-- Owen

-- 
You received this message because you are subscribed to the Google Groups 
"pocoo-libs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pocoo-libs.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to