templates

79 views
Skip to first unread message

Ranganath s

unread,
Sep 29, 2010, 2:29:23 AM9/29/10
to we...@googlegroups.com, Anand Chitipothu
Hi group,

      I need some clarification on template inheritance of templator template of webpy. say i have basic.html and xyz.html. If i need to extend xyz.html from basic.html, how do i go about doing that ? can some one please throw light on this.

Regards,
Ranganath.S

--
I blog at http://ranganaths.wordpress.com

Zhang Huangbin

unread,
Sep 29, 2010, 3:42:14 AM9/29/10
to we...@googlegroups.com

On Sep 29, 2010, at 2:29 PM, Ranganath s wrote:

> Hi group,
>
> I need some clarification on template inheritance of templator template of webpy. say i have basic.html and xyz.html. If i need to extend xyz.html from basic.html, how do i go about doing that ? can some one please throw light on this.

Is it what you want?
http://webpy.org/cookbook/layout_template

Branko Vukelic

unread,
Sep 29, 2010, 5:20:14 AM9/29/10
to we...@googlegroups.com, Anand Chitipothu
On Wed, Sep 29, 2010 at 8:29 AM, Ranganath s <ranga...@gmail.com> wrote:
> Hi group,
>       I need some clarification on template inheritance of templator
> template of webpy. say i have basic.html and xyz.html. If i need to extend
> xyz.html from basic.html, how do i go about doing that ? can some one please

Basic concept is that any template accepts any variable you define in
the ``$def with`` line. That includes templates, naturally. For any
template, you can also define attributes with ``$var`` line. So, if
you have this in xyz:

$var title: My tempalte's title

and this in base:

$def with (child_template)

You can pass the child template as a variable to base template:

render.base(render.xyz())

and in base you can:

$:child_template

or:

<title>$child_template.title</title>

It's actually quite flexible, as you can see.

--
Branko Vukelić

bg.b...@gmail.com
stu...@brankovukelic.com

Check out my blog: http://www.brankovukelic.com/
Check out my portfolio: http://www.flickr.com/photos/foxbunny/
Registered Linux user #438078 (http://counter.li.org/)
I hang out on identi.ca: http://identi.ca/foxbunny

Gimp Brushmakers Guild
http://bit.ly/gbg-group

Anand Chitipothu

unread,
Sep 29, 2010, 6:28:49 AM9/29/10
to Ranganath s, we...@googlegroups.com
2010/9/29 Ranganath s <ranga...@gmail.com>:

> Hi group,
>       I need some clarification on template inheritance of templator
> template of webpy. say i have basic.html and xyz.html. If i need to extend
> xyz.html from basic.html, how do i go about doing that ? can some one please
> throw light on this.

Templates really like python functions.

If you want to support something like layout template, then you need
to do like this:

render.layout(render.page(page))

Anand

Ranganath s

unread,
Sep 29, 2010, 6:30:04 AM9/29/10
to Anand Chitipothu, we...@googlegroups.com
Thanks a lot guys, i really appreciate your time in explaining the concept.

Thank you
Ranganath.S

andrei

unread,
Sep 29, 2010, 7:53:44 AM9/29/10
to web.py
Another way is to define render function in the template globals, like
this:

template_globals = {}
render_partial = web.template.render(rootdir+'/templates/',
globals=template_globals)
render = web.template.render(rootdir+'/templates/',
globals=template_globals, base='layout')
template_globals.update(render=render_partial)


Then you will be able to call $:render.any_template() in templates.



On Sep 29, 2:30 pm, Ranganath s <rangana...@gmail.com> wrote:
> Thanks a lot guys, i really appreciate your time in explaining the concept.
>
> Thank you
> Ranganath.S
>
> On Wed, Sep 29, 2010 at 3:58 PM, Anand Chitipothu <anandol...@gmail.com>wrote:
>
>
>
>
>
> > 2010/9/29 Ranganath s <rangana...@gmail.com>:

Greg Milby

unread,
Sep 29, 2010, 10:19:38 AM9/29/10
to we...@googlegroups.com
So, in base.html, if i had:
$def with (var1, var2, render.xyz())
it will globally render against any template that is evaluated in the base.html (called from the render in code)?
If so, it would be curious to know if variables for pagination, current link, other base-type functions could be passed in.
i'll play with the first part first :)


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


Branko Vukelic

unread,
Sep 29, 2010, 10:24:53 AM9/29/10
to we...@googlegroups.com
On Wed, Sep 29, 2010 at 4:19 PM, Greg Milby <gmi...@gmail.com> wrote:
> So, in base.html, if i had:
> $def with (var1, var2, render.xyz())

You can't have a method call there. You could pass render.xyz() to
base, which is what I described in my reply.

> it will globally render against any template that is evaluated in the
> base.html (called from the render in code)?

I don't understand the concept of 'global rendering', but the template
instance will act just like any other variable you care passing to the
template.

> If so, it would be curious to know if variables for pagination, current
> link, other base-type functions could be passed in.
> i'll play with the first part first :)

It's like arguments for a function, really. If you know what x, y, and
z mean in:

def myfunc(x, y, z):
pass

then you can apply the same to Templetor templates.

Greg Milby

unread,
Sep 29, 2010, 6:45:00 PM9/29/10
to we...@googlegroups.com

This nvr seems to finish loading?  http://milby.no-ip.org:8080/appointments/?action=register

::Sent from my Verizon HTC incredible gOS::

Reply all
Reply to author
Forward
0 new messages