Includes query

1 view
Skip to first unread message

Martin

unread,
Aug 28, 2007, 7:03:30 AM8/28/07
to brevé template engine, li...@martinpp.co.uk

Hello again,

I am really starting to enjoy using Breve (the other day I even went
to write some basic html and found myself writing html [ .. ] before
realising I should be using <html></html>). However, I am now stumped
on how the includes directive works.

Essentially I will be including the same template several times in
another template:

view.b
-----------
inherits ('site') [
override ('content') [
include ('widget', vars={'widgetId':1}),
include ('widget', vars={'widgetId':2}),
include ('widget', vars={'widgetId':3}),
]
]

widget.b
-------------
invisible [
'Widget ID %s' %
variables.widgetId
]

I would expect here that the output has the three widgets with their
different id's shown (1,2 and 3). However, I end up getting 1,1 and 1.
Looking at the source I see that the T vars stomps the passed
variables in the update and I am curious as to why this is the case
and how to make the above work.

def include (T, filename, vars = None, loader = None):
locals = Namespace (vars)
# Locals correctly contains widgetId for each widget
try:
locals._dict.update (T.vars [ T.vars [ '__namespace' ] ])
except KeyError:
locals._dict.update (T.vars)
# Locals widgetId value has now been replaced by first value
stored by T.vars?
return xml ( T.render_partial ( template = filename, loader =
loader, vars = locals ) )


Thank you in advance,


Martin

Cliff Wells

unread,
Aug 28, 2007, 2:09:41 PM8/28/07
to breve-...@googlegroups.com, li...@martinpp.co.uk
On Tue, 2007-08-28 at 04:03 -0700, Martin wrote:

> I would expect here that the output has the three widgets with their
> different id's shown (1,2 and 3). However, I end up getting 1,1 and 1.
> Looking at the source I see that the T vars stomps the passed
> variables in the update and I am curious as to why this is the case
> and how to make the above work.
>
> def include (T, filename, vars = None, loader = None):
> locals = Namespace (vars)
> # Locals correctly contains widgetId for each widget
> try:
> locals._dict.update (T.vars [ T.vars [ '__namespace' ] ])
> except KeyError:
> locals._dict.update (T.vars)
> # Locals widgetId value has now been replaced by first value
> stored by T.vars?
> return xml ( T.render_partial ( template = filename, loader =
> loader, vars = locals ) )

Looks like a bug to me. I'll get it fixed. Thanks for the report.


BTW, you don't need "invisible" any more for this type of thing. The
docs are slightly out of date and you can now have multiple fragments in
a file:

# widget.b

'Widget ID %s' % variables.widgetId,
div, span

The limitation to have them all within in a single container node per
file is no longer necessary.


Regards,
Cliff

Martin

unread,
Aug 29, 2007, 11:31:04 AM8/29/07
to brevé template engine

> Looks like a bug to me. I'll get it fixed. Thanks for the report.
No problem.


> BTW, you don't need "invisible" any more for this type of thing. The
> docs are slightly out of date and you can now have multiple fragments in
> a file:

Cheers for the pointer and thanks also for the quick response.


Martin

Reply all
Reply to author
Forward
0 new messages