I actually tried your code and it worked well after I fixed a small issue:

         return getattr(self.render, self.base)(content, **base_args)
-->
         return getattr(self.render, self.base)(content, **self.base_args)

Thanks!

On Thu, Jan 28, 2010 at 1:42 AM, Pablo Antonio <[email protected]> wrote:
> You could do something like the following code. Be aware that I didn't
> test it, and it looks like too much magic :) Here it is:
>
> -- layout.html
> $def with (content, visitor_numbers)
> <p>Numbers: $visitor_numbers</p>
> <p>$:content</p>
>
> -- pages.py
>
> import web
>
> class RenderInContext:
>
>    def __init__(self, dir = 'templates/', base, **base_args):
>        self.render = web.template.render(dir)
>        self.base = base
>        self.base_args = base_args
>
>    def __getattr__(self, tpl):
>
>        def f(**tpl_args):
>            content = getattr(self.render, tpl)(**tpl_args)
>            return getattr(self.render, self.base)(content, **base_args)
>
>        return f
>
> render_in_context = RenderInContext('templates/', base = 'layout',
>    visitor_numbers = '20')
>
> render_in_context.index(foo = bar)

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.

Reply via email to