Sending Variables up the template stream?

13 views
Skip to first unread message

Colin Davis

unread,
Mar 15, 2013, 12:20:22 AM3/15/13
to Tornado Web Server
If I have two templates-

Foo.html
<html>
Hello, {{name}}
{% block something %}
something!
{% end %}


And Bar.html
{% extends Foo.html %}
{% block something %}
Something Else!!
{% end %}


How can I call Bar.html and pass in the variable name?

Calling it the 'normal' way-
self.write(self.render_string('Bar.html',
name="Alice"))

Doesn't seem to pass the name upstream for insertion in Foo.html..

What's the right way to handle this?
I'm sure I'm missing something obvious, but I could use any advice.

-CPD

aliane abdelouahab

unread,
Mar 15, 2013, 10:42:17 AM3/15/13
to Tornado Web Server
if you add this variable to Bar, this will work?
does this means that extends will not look at its variable?

Colin Davis

unread,
Mar 15, 2013, 5:16:22 PM3/15/13
to python-...@googlegroups.com
That's exactly the problem ;)
Right now, it doesn't seem to work.
With a Jinja template, for instance, it does.

aliane abdelouahab

unread,
Mar 15, 2013, 6:03:34 PM3/15/13
to Tornado Web Server
bizarre, here it works.
because if tornado will not find the variable it will return an error!

aliane abdelouahab

unread,
Mar 15, 2013, 6:05:46 PM3/15/13
to Tornado Web Server
here is the file:

foo.html is the header, bar.html is the file you want to render, when
you call self.render(bar.html, x='hello') and if {{x}} is in foo.html
it will be rendered as hello! it always take the latest file that will
be meged with the parent.

On 15 mar, 22:16, Colin Davis <cir...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages