If you benefit from web2py hope you feel encouraged to pay it forward by contributing back to society in whatever form you choose!

Django has a different template inheritance pattern (http://docs.djangoproject.com/en/1.2/topics/templates/#template-inheritance) which encourages the use of multiple blocks that can be overriden by a child template.

You can should achieve a similiar behaviour in this way:

<!-- layout.html -->
<html>
    <head>
        {{ def block(): }}
             <p>This is the layout's block!</p>
        {{ pass }}
        {{ include }}
    </head>
    <body>
        {{ block() }}
    </body>
</html>

<!-- hello.html -->
{{ extend 'layout.html' }}
{{ def block(): }}
    <p>Hello there block users!</p>
{{ pass }}

Comments (1)

  • Login to post



  • 0
    thadeusb 14 years ago
    Soon (probably web2py 1.80 or 1.80.1) the new web2py template system will support blocks. Note it will also support super syntax, to include the parent blocks content. {{block title}}Default Title{{end}} {{block content}} Nothing here... {{end}} {{ extend 'layout.html' }} {{block title}} Hello World {{end}} {{block content}} Hello there block users! {{super}} {{end }}

Hosting graciously provided by:
Python Anywhere