Strange NameError in Mako Templates

30 views
Skip to first unread message

Moritz Schlarb

unread,
Apr 5, 2012, 12:18:00 PM4/5/12
to turbo...@googlegroups.com
Hi there!

I'm not sure if this is more related to tg, pylons or mako, so I
thought, I'd just ask here.

The source code:

<%def name="event_list(events)">

<dl>
% for event in events:
## <dt>${h.link(event.name, tg.url('/events/%s' % event.url))}
(${event.type | string.capitalize})</dt>
<dt>${event.link} (${event.type | string.capitalize})</dt>
<dd>${event.description | n, h.striphtml, h.cut }</dd>
% endfor
</dl>

</%def>

throws

NameError: global name 'h' is not defined

with that line commented out.
When I remove the commenting, it works (except for that I get the link
generated twice).

Pylons Traceback:
http://pylonshq.com/tracebacks/a133f8a44af50ae18c806ab32160f8b0

It seems as if lib.helpers as h isn't imported when I only access the
property as a filter.
Or could it be related to that I'm just defining a function? I use
namespace to import the needed function from a generic lists.mak into
the rendered templates.

Please help! ;)

Alessandro Molina

unread,
Apr 5, 2012, 3:39:26 PM4/5/12
to turbo...@googlegroups.com
I'm not a mako user myself, so I'm not sure how mako filters are
handled inside mako itself.

What I can tell you is that the 'h' variable is injected by TG itself
every time the controller renders a template registered using @expose.
So if you render the template manually the h variable won't be available.
Also if you render a template inside a template the h variable must be
explicitly passed to the second template.

I don't know if this is the case.

> --
> You received this message because you are subscribed to the Google Groups "TurboGears" group.
> To post to this group, send email to turbo...@googlegroups.com.
> To unsubscribe from this group, send email to turbogears+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.
>

Reply all
Reply to author
Forward
0 new messages