Just in case someone needs this... I now have a working module. It "resolves" via the source files - no context, no "real rendering". Therefore only literal string parameters are supported for the template paths of {% extends ... %} and {% include ... %}. That's ok for my current purposes. Otherwise I don't see any drawbacks, and it handles multiple inheritance and nested blocks just fine.
If anyone ever runs across the problem of having to "flatten" django templates, happy to provide the source (130 lines incl. lots of comments, bit much for email) The main issue I had to tackle were nested {% block ... %} across inherited templates. After 1. failing with regular expressions (they can't balance the opening with their corresponding closing tags, for arbitrary levels of nesting), 2. failing with pyparsing (I still think there could be an elegant pyparsing solution, but blocks have different names - they're not just nested parantheses - so nestedExpr() gets a little more complicated here - I believe similar issue to http://pyparsing.wikispaces.com/message/view/home/8771774). 3. failing with Node objects. They lose the original source ("origin") unless TEMPLATE_DEBUG=True. I subclassed and forced the source to always be kept, but realized that the source is not kept per node, rather the complete source is kept (per ExtendsNode) together with start and end index of where (just the opening of!) the tag was found. 4. the end result looks like a stripped down sgml parser - iterative regex finding, cutting up, together with matching corresponding {% endblock %}'s and some simple string replacements. Cheers, Danny On Tue, Jan 11, 2011 at 10:51, Danny W. Adair <danny.ad...@unfold.co.nz> wrote: > Hi, > I need to get the template source of a template "after inheritance", > i.e. render just the loader tags "include", "extends" and > "block" (incl. variable block.super), so that I end up with one > independent template which is otherwise unrendered. > > Has anyone done this before or has pointers? > > I'm still undecided whether to work with Node objects (maybe borrowing > some ideas from http://djangosnippets.org/snippets/769/ ) or just use > regex on the source and manually "glue together". > > Any help greatly appreciated. > > Cheers, > Danny > -- Kind regards, Danny W. Adair Director Unfold Limited New Zealand Talk: +64 - 9 - 9555 101 Fax: +64 - 9 - 9555 111 Write: danny.ad...@unfold.co.nz Browse: www.unfold.co.nz Visit/Post: 253 Paihia Road, RD 2, Kawakawa 0282, New Zealand "We are what we repeatedly do. Excellence, then, is not an act but a habit." ============================== Caution The contents of this email and any attachments contain information which is CONFIDENTIAL to the recipient. If you are not the intended recipient, you must not read, use, distribute, copy or retain this email or its attachments. If you have received this email in error, please notify us immediately by return email or collect telephone call and delete this email. Thank you. We do not accept any responsibility for any changes made to this email or any attachment after transmission from us. ============================== -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.