O'Reilly logo

Python 2.6 Text Processing Beginner's Guide by Jeff McNeil

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - creating custom Mako tags

The concept of custom tags and defs-with-content blocks probably seems slightly confusing. It is a powerful feature, though, so here we'll take a closer look at it. In this example, we'll create a simple template, which produces an HTML layout.

  1. Create a new template and name it page.html. Enter the following Mako template code:
     <%doc> This def creates the layout for our page. Calling it generates an entire HTML layout. </%doc> <%def name="create_page()"> <html> <head> <title> ${caller.title()} </title> </head> <body> <h1>${caller.header()}</h1> <hr/> ${caller.body()} <hr/> ## Inline styles for example purposes. <div style="font-size: .5em; color: grey;"> ${caller.footer()} </div> </body> </html> </%def> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required