template functions scope

27 views
Skip to first unread message

Alex K

unread,
Oct 2, 2011, 9:41:39 AM10/2/11
to we...@googlegroups.com
Suppose I have some functions in a template defined with "$def func_name". Can I call these functions from another template?

Thank you

Dragan Espenschied

unread,
Oct 3, 2011, 2:27:56 AM10/3/11
to we...@googlegroups.com
Such a function should be put into your code.py.

Then make it accessible to the templates like this:

def myfunc(lol):
pass


render = web.template.render('templates/', globals={'myfunc':myfunc})

> --
> You received this message because you are subscribed to the Google Groups
> "web.py" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/webpy/-/hLiDxn3Y5XkJ.
> To post to this group, send email to we...@googlegroups.com.
> To unsubscribe from this group, send email to webpy+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/webpy?hl=en.

--
http://noobz.cc/
http://digitalfolklore.org/
http://contemporary-home-computing.org/1tb/

Alex K

unread,
Oct 16, 2011, 1:20:31 PM10/16/11
to we...@googlegroups.com
That is not exactly it because I'd like to write these functions in templetor. Instead I think I would rather nest the render calls ... that is render the templates which hold the functions separately and pass them on to a new template which takes these as variables. But is there a better way?
Reply all
Reply to author
Forward
0 new messages