Help! Problems using ${ .. } (Kid/template notation) with Python **classes**!

0 views
Skip to first unread message

sebe...@spawar.navy.mil

unread,
Dec 9, 2006, 8:21:11 PM12/9/06
to TurboGears
I created a Python class called Company with some info I want to access
in template.

Should my controller return something like this?...

return {"my_object" : some_instance_of_Company}

If so, how access in templates??? Like this?...


${my_object["some_key"] } ???

Thanks!

BTW,

I'm confused because keys are usually strings but you don't quote them
in templates.
e.g. ${my_string} is right rather than ${"my_string"} why?

chris

Christoph Zwerschke

unread,
Dec 9, 2006, 9:44:13 PM12/9/06
to turbo...@googlegroups.com
sebe...@spawar.navy.mil wrote:
> I created a Python class called Company with some info I want to access
> in template.
> Should my controller return something like this?...
> return {"my_object" : some_instance_of_Company}
> If so, how access in templates??? Like this?...
> ${my_object["some_key"] } ???

Depends where you want to access it. Inside py: attributes and <?python>
PIs you would access it simply as my_object; inside other attributes and
ordinary HTML you would write ${my_object} or short $my_object.

> I'm confused because keys are usually strings but you don't quote them
> in templates.
> e.g. ${my_string} is right rather than ${"my_string"} why?

This is explained here:
http://kid-templating.org/guide.html#template-variables

-- Christoph

Reply all
Reply to author
Forward
0 new messages