Skip to content

Latest commit

 

History

History
79 lines (60 loc) · 1.89 KB

README.md

File metadata and controls

79 lines (60 loc) · 1.89 KB

CI Status image image

more.mako

more.mako is an extension for Morepath that adds Mako template support when you use the .mako extension.

Example usage:

from more.mako import MakoApp

class App(MakoApp):
    pass

@App.path(path='persons/{name}')
class Person(object):
   def __init__(self, name):
       self.name = name

@App.template_directory()
def get_template_directory():
    return 'templates'

@App.html(model=Person, template='person.mako')
def person_default(self, request):
    return {'name': self.name}

and then in person.mako in the templates subdirectory:

<html>
  <body>
    <p>Hello {{name}}!</p>
  </body>
</html>

You can also render defs from templates using the special syntax template#defname.mako like the following example:

@App.html(model=Root, template='defs#hello.mako')
def hello():
    return {'name': 'World'}

and then in defs.mako:

<%def name="hello(name)">
<p>Hello ${name}!</p>
</%def>

Note that the Mako documentation uses the .html extension for Mako templates, whereas this extension uses .mako instead.

To control Mako behavior you can define a mako setting section in your app, for instance:

@App.setting_section(section='mako')
def get_setting_section():
    return {
        'default_filters': ['h'],
        'format_exceptions': True
    }

For details on Mako configuration options, consult the Mako API documentation.