Implementation of "content_for" template blocks

31 views
Skip to first unread message

Andrey Kuzmin

unread,
Nov 25, 2012, 8:50:38 AM11/25/12
to we...@googlegroups.com
Hello

I've had some troubles when child templates need to provide some content for the parent templates. 

My first approach was setting $var in child template, and access it from parent template. But this approach has obvious limitation: you cannot provide more complex content than just one string (yes you can by setting $var to sub-sub-template output, but this is not flexible).

Instead of this I implemented a special content_for code block, that outputs contents to web.ctx, so then parent templates may output them.

Child template:

    $content_for("header"):
        <p>Some content for header</p>

Parent template:

    $:content_for("header")


My first implementation was dirty, but then I found out how to make it nicer by hiding functionality in generated template code

I'm not sure if this feature can make its way in web.py code, but I'd like to get some feedback from web.py users.


Andrey Kuzmin

unread,
Nov 26, 2012, 5:38:17 AM11/26/12
to we...@googlegroups.com
I'm sad no one really finds this useful. I mostly work on the front-end and really need this template functionality.

Andrey Kuzmin

unread,
Nov 26, 2012, 12:18:00 PM11/26/12
to we...@googlegroups.com
It appears that $var statement can be multiline, so there is not much need in my proposal. The only difference is that it appends content to defined section so content from multiple $content_for blocks can be included in one section.  
Reply all
Reply to author
Forward
0 new messages