debugging template

72 views
Skip to first unread message

techtonik

unread,
Sep 11, 2009, 12:34:48 PM9/11/09
to Genshi
Hello,

Is there any debug template for Genshi that allows to inspect all
available variables in template?

I am asking, because coming from PHP world where Smarty is almost a
standard, there is very convenient {debug} function that embeds popup
window with accessible variables into page content.
http://www.smarty.net/manual/en/chapter.debugging.console.php

For example I need to get URL of the current page in Trac template,
but I do not how is it called and if it available at all.

--
anatoly t.

Erik Bray

unread,
Sep 11, 2009, 2:46:50 PM9/11/09
to gen...@googlegroups.com

You could try putting ${locals()['__data__']} in your template somewhere.

Jeff Hammel

unread,
Sep 11, 2009, 2:53:52 PM9/11/09
to gen...@googlegroups.com

Sweet. I've been wanting that for a long time (should have though of that myself). Thanks.

Jeff

techtonik

unread,
Sep 11, 2009, 4:19:19 PM9/11/09
to Genshi
On Sep 11, 9:46 pm, Erik Bray <hyugaricd...@gmail.com> wrote:
>
> > Is there any debug template for Genshi that allows to inspect all
> > available variables in template?
>
> You could try putting ${locals()['__data__']} in your template somewhere.

Great tip! Thank you. But is there a way to make the output more
pretty-printed? Right now I have about 32kBytes of data all inserted
into one line in generated XML.

--
anatoly t.

Jeff Hammel

unread,
Sep 11, 2009, 4:24:05 PM9/11/09
to gen...@googlegroups.com

I mean, its python so you can do whatever you want. E.g.

<pre>
${'\n'.join(locals()['__data__'])}
</pre>

Or whatever

Jeff

Erik Bray

unread,
Sep 11, 2009, 4:47:08 PM9/11/09
to gen...@googlegroups.com

Or better yet, create a function and save it in a utils template. For example:

<table py:def="debug" class="debug">
<thead>
<tr><th colspan="2">Template Variables</th></tr>
<tr><th>Name</th><th>Value</th></tr>
<thead>
<tbody>
<tr py:for="key, value in locals()['__data__']">
<td>${key}</td><td>${repr(value)}</td>
</tr>
</tbody>
</table>

${debug()}

techtonik

unread,
Sep 11, 2009, 5:21:24 PM9/11/09
to Genshi
Unfortunately, both of these fail with KeyError in my case:

File "m:\p\trac\trac-0.11dev\trac\timeline\templates\timeline.rss",
line 19, in <Expression u"'\\n'.join(locals()['__data__'])">
${'\n'.join(locals()['__data__'])}
File "m:\p\trac\genshi-0.5dev\genshi\template\base.py", line 184, in
__getitem__
raise KeyError(key)

--
anatoly t.

techtonik

unread,
Sep 11, 2009, 6:20:17 PM9/11/09
to Genshi
Finally got it to work in Trac with:

${pprint(dict(locals()['__data__']))}

Seems like a bug in Genshi Context. Going to fill some bugs now.
Thanks for hints once more.

--
anatoly t.
Reply all
Reply to author
Forward
0 new messages