On Thu, Jan 28, 2010 at 9:40 AM, iltriki <[email protected]> wrote:
>> Branko already answered, and he was very clear, but just in case
>> you need some example code, take a look at this 
>> thread:http://groups.google.com/group/webpy/browse_thread/thread/93afa0c8eb3...
>
> Thank you guys..
> do i need to use $var or can i just use variables that i get from def?
>
> Imagine an index.html view with this:
> $def with (visitor_numbers)
>
> can i just use $context.visitor_numbers inside layout.html?

$var is a bit misleading. It doesn't define a new variable, but a
$content attribute. You can also access that attribute from a regular
Python script:

t = render.temapate_that_defines_var()
t.new_attribute

So, if you want to pass something to the base template, you have to use $var.

There is another way:

def render_via_base(content, **kwargs):
    render.base_template(content, **kwargs)

Then use it like this:

render_via_base(render.your_template(arg="for your template"),
                arg="for the base template")

It's nothing special, just regular Python.

>
> Another thing..
> with this scenario, i need to replicate the call to
> get_visitor_numbers method inside every classes of my controller, and
> then pass the returned value to the views.
> Is there a more elegant way in web.py to handle this?
> Thanks
>
> Michele
>
> --
> 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.
>
>



-- 
Branko Vukelić

http://foxbunny.tumblr.com/
http://www.flickr.com/photos/16889...@n04/
http://www.twitter.com/foxbunny
http://github.com/foxbunny

-- 
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