Accessing the code of the currenly executing template in Pyramid

36 views
Skip to first unread message

Hollister

unread,
Oct 13, 2012, 9:40:36 PM10/13/12
to mako-d...@googlegroups.com
Access to a template's context.lookup is great for debugging, and works perfectly when I use TemplateLookup and Template classes directly.

I've been trying to get this to work within Pyramid, which obviously calls TemplateLookup and Template on my behalf, but I'm missing something. When I access the lookup property within the template code, I don't get the introspection object I think I want. I'd like to be able to <% log.debug(context.lookup.get_template("this template right now").code) %> kind of thing.

If I pass in the name of the template, everything works fine, but I'd like to make this generic and just "aware".

Is there a way to get the name of the currently executing template? 

Michael Bayer

unread,
Oct 15, 2012, 11:41:03 AM10/15/12
to mako-d...@googlegroups.com

Inside of any template, the "local" namespace represents the current template (if the template doesn't refer to it, you need to say "context['local']" to get this).

"local.uri" will give you the URI of the current template, "local.template" is the actual Template object, and "local.template.code" is the source code.




--
You received this message because you are subscribed to the Google Groups "Mako Templates for Python" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mako-discuss/-/bvOj2Av0EYAJ.
To post to this group, send email to mako-d...@googlegroups.com.
To unsubscribe from this group, send email to mako-discuss...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mako-discuss?hl=en.

Reply all
Reply to author
Forward
0 new messages