librelist archives

« back to archive

render partial problem

render partial problem

From:
Lix Xu
Date:
2010-06-25 @ 01:15
Hi,
     I encountered below problem:
     I have layout.html, users/index.html, users/_user.html.
     users/_user.html is a partial template (like render_partial in Rails)
that can be used for users/index and users/show.
     But the problem is: there is <span id='flash_msg'></span> in
layout.html for showing flash messages, and render_user in _user.html for
rendering users,

     in users/index.html:
    ...
    {% from '_user.html' import render_user %}
    {{ render_user(users) }}
    ...

     but this <span /> can't be used in _user.html.

     Is there any solution for this problem?

     Thanks a lot.

Lix Xu

Re: [flask] render partial problem

From:
Simon Sapin
Date:
2010-06-25 @ 04:45
Hi,

Not sure it can help you, but there is Jinja’s “Null-master fallback” 
trick :
http://jinja.pocoo.org/2/documentation/tricks#null-master-fallback

Basically, with inheritance, everything outside a {% block %} is ignored 
in child templates. You could have your <span id='flash_msg'></span> 
there and make inheritance conditional, as described above.

-- 
Simon Sapin