Search code examples
htmlweb2pyweb2py-modules

web2py - How do I insert html with {{block ...}} in it into another html?


view1.html:

{{block left_sidebar}}
asdf
{{end}}

debug.html:

{{left_sidebar_enabled = True}}
{{extend 'layout.html'}}
{{include 'view1.html'}}

controller:

def debug():
    return {}

The content from view1.html doesn't appear and I don't understand why.

If I modify view1.html as follows:

{{block left_sidebar}}
asdf
{{end}}
qwer

qwer does appear on the page but not asdf.

Any help appreciated.


Solution

  • Blocks go in extending views, not in included views (i.e., an extending view can define a block that also exists in the view it extends, and the block in the extending view will replace the block in the extended view). So:

    {{block left_sidebar}}
    asdf
    {{end}}
    

    would go in debug.html (not in view.html), in which case it will replace the left_sidebar block in layout.html.