Template file name always output file name?

46 views
Skip to first unread message

Christian Wutte

unread,
Feb 7, 2012, 5:54:38 PM2/7/12
to Mako Templates for Python
Hello there,
I have another question: is it possible to set the output filename
independently from the template file?

Thank you, BR,
Christian

Michael Bayer

unread,
Feb 7, 2012, 6:05:04 PM2/7/12
to mako-d...@googlegroups.com

On Feb 7, 2012, at 5:54 PM, Christian Wutte wrote:

> Hello there,
> I have another question: is it possible to set the output filename
> independently from the template file?
>

sure, Template accepts a parameter module_filename that overrides the filename, and TemplateLookup accepts a parameter modulename_callable so that you can pass a function which applies a naming scheme to all templates.

def name_module(source_path, uri):
return os.path.abspath(
os.path.join(
os.path.normpath("/var/tmp"),
uri + ".py"
)
)

lookup = TemplateLookup(directories="/foo/bar", modulename_callable=name_module)

docs:

http://docs.makotemplates.org/en/latest/usage.html#mako.lookup.TemplateLookup
http://docs.makotemplates.org/en/latest/usage.html#mako.template.Template


> Thank you, BR,
> Christian
>
> --
> You received this message because you are subscribed to the Google Groups "Mako Templates for Python" group.
> To post to this group, send email to mako-d...@googlegroups.com.
> To unsubscribe from this group, send email to mako-discuss...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mako-discuss?hl=en.
>

Reply all
Reply to author
Forward
0 new messages