-
-
Notifications
You must be signed in to change notification settings - Fork 69
Description
Migrated issue, originally created by Michael Bayer (@zzzeek)
pretty intuitive, the block is essentially just like a def except it invokes immediately.
<%block filter="w">
some text
</%block>
is equivalent to:
<%def name="_anon_1()" filter="w">
some text
</%def>${_anon_1()}
where "_anon_1" is generated, except that there is no "_anon_1" def which is "exported". Blocks are more private than top-level defs.
The block can of course have a name, which is generally for when inheritance is used. The rules then change a bit:
<%block name="header">
some text
</%block>
is equivalent to, minus the top level def export:
<%def name="header()">
some text
</%def>${self.header() if not hasattr(parent, 'header')}
i.e. named blocks exec off of self and only if the parent doesn't have such a block. That way, the bottommost template in an inheritance chain determines when a block of a certain name occurs, giving us the jinja2 system of inheritance:
base.mako:
<html>
<head>
<title>
<%block name="title">
the homepage
</%block>
</title>
<body>
</body>
</html>
index.mako:
<%inherit file="base.mako"/>
<%block name="title">
the index
</%block>
Attachments: 164.3.patch | 164.patch | 164.2.patch