You can put any object (functions, bound methods, macros, etc.) into env.globals, same way you're adding filters:
http://jinja.pocoo.org/docs/dev/api/#jinja2.Environment.globals If you specifically want to pass in a macro, compile the template that contains your macro, then add template_obj.module.macroname to env.globals: http://jinja.pocoo.org/docs/dev/api/#jinja2.Template.module -Steve On Mon, Dec 22, 2014 at 6:26 AM, Alexander Todorov <[email protected]> wrote: > Hi guys, > for filters we can easily define our own by: > > env.filters['myfilter'] = myfunc > > I'm looking to do something similar but for macros. I don't see any > obvious way so any pointers/helpers are welcome. > > My goal is to provide a default environment with domain specific macros > and filters but not require template designers to import additional files. > > Thanks, > Alex > > -- > You received this message because you are subscribed to the Google Groups > "pocoo-libs" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/pocoo-libs. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "pocoo-libs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/pocoo-libs. For more options, visit https://groups.google.com/d/optout.
