Issues

Issue #215 new

warn/raise when a def/block is named "body"

guest
created an issue

Hi,

I was trying out mako and found a peculiar issue. If I have the name of a block as "body" the inheritance won't work. I am attaching the output of before and after ... this is a very simple example.

## layout.html
<title> Hello </title>
<%block name="body">Parent body </%block>


## show_entries.html

<%inherit file="layout.html" />

<%block name="body" >
Body of show entries
</%block>

Code for rendering

templ = temp_lookup.get_template('show_entries.html')
print templ.render()

Output :

In [64]: print templ.render()
Parent body

In [65]: print templ.render()
Parent body

In [66]: templ = temp_lookup.get_template('show_entries.html')

In [67]: print templ.render()
Parent body

After changing the name="body" to name="body_2" in both

In [68]: templ = temp_lookup.get_template('show_entries.html') In [69]: print templ.render()

<title> Hello </title>

Body of show entries

Comments (1)

  1. Mike Bayer repo owner

    well "body" is a reserved name, and is treated differently. I can't find the issue where this was mentioned before, maybe it was a mailing list mail. Should probably emit a warning when this name is used, emitting an error would be better but not sure if that breaks some folks who might be relying upon a name "body".

  2. Log in to comment