How to call an imported function with embedded content?

31 views
Skip to first unread message

Дмитрий Архипов

unread,
Feb 15, 2017, 8:07:51 AM2/15/17
to Mako Templates for Python
Suppose I have a def block named "foo" in a template.
I use that template as a namepace and import the function from it:
 
<%namespace file="lib.mako" import="foo"/>

How do I use the imported function with embedded content?

This doesn't work:

<%self.foo>
  text...
</%self.foo>

mike bayer

unread,
Feb 16, 2017, 9:25:08 AM2/16/17
to mako-d...@googlegroups.com
I don't think there's an "implicit" namespace available right now so
you'd need to give your <%namespace> a local name and use that the way
it is in the docs:


<%namespace file="lib.mako" name="mylib">

<%mylib.foo>
</%mylib.foo>


otherwise you can use the <%call> tag directly which is kind of old school

<%call expr="foo()">
text
</%call>




>
> --
> You received this message because you are subscribed to the Google
> Groups "Mako Templates for Python" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to mako-discuss...@googlegroups.com
> <mailto:mako-discuss...@googlegroups.com>.
> To post to this group, send email to mako-d...@googlegroups.com
> <mailto:mako-d...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/mako-discuss.
> For more options, visit https://groups.google.com/d/optout.

Дмитрий Архипов

unread,
Feb 17, 2017, 8:32:26 AM2/17/17
to Mako Templates for Python
Ok, thanks.

четверг, 16 февраля 2017 г., 17:25:08 UTC+3 пользователь mike bayer написал:


On 02/15/2017 08:07 AM, Дмитрий Архипов wrote:
> Suppose I have a def block named "foo" in a template.
> I use that template as a namepace and import the function from it:
>
> <%namespace file="lib.mako" import="foo"/>
>
> How do I use the imported function with embedded content?
>
> This doesn't work:
>
> <%self.foo>
>   text...
> </%self.foo>


I don't think there's an "implicit" namespace available right now so
you'd need to give your <%namespace> a local name and use that the way
it is in the docs:


<%namespace file="lib.mako" name="mylib">

<%mylib.foo>
</%mylib.foo>


otherwise you can use the <%call> tag directly which is kind of old school

<%call expr="foo()">
    text
</%call>




>
> --
> You received this message because you are subscribed to the Google
> Groups "Mako Templates for Python" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to mako-discuss...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages