New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add blocks #164

Closed
sqlalchemy-bot opened this Issue Mar 8, 2011 · 2 comments

Comments

Projects
None yet
1 participant
@sqlalchemy-bot

sqlalchemy-bot commented Mar 8, 2011

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

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Apr 6, 2011

Michael Bayer (@zzzeek) wrote:

hooray !

4a19e4d

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Apr 6, 2011

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment