Am 20.07.2010 um 21:41 schrieb Guyren G Howe:
On Jul 20, 2010, at 6:54 , Diez B. Roggisch wrote:
I don't get it. Why don't you just return d? Everything that is
supposed
to be template-only, e.g. widgets or helper functions or no idea
what
else is supposed to go to the tmpl_context anyway. Precisely
because
otherwise rendering json would mean rendering cruft.
If I return d and it's a dictionary, I don't know how to refer to
it in the
template.
By the keys of the dictionary. As you already do, with an unneeded
layer of
indirection.
The object has a lot of fields. I wanted to be able to get at the
dictionary as a whole and iterate through its keys and values to
display them, rather than manually typing it all out. But there
doesn't appear to be a way of getting at just that dictionary of
values from the template unless I first wrap it in an outer
dictionary.
It would have helped tremendously if you had expressed that way of
working with the dict from the very beginning.
However, no, there is no way of implicitly returning something beneath
a key for HTML rendering, and all of a sudden for JSON get rid of that
key.
But I've already mentioned tmpl_context, and it is the solution here.
Return your object as such, and also stuff it into tmpl_context under
a key of your choice. Then in the template, do
<py:for each="key, value in c.my_fancy_object.iteritems()"> ...
Also: is there a better way to get the fields of the object as a dict?
Not that I know of. I find the jsonification of TG2 lacking compared
to TG1, but then I might miss something myself.
Diez
--
You received this message because you are subscribed to the Google Groups
"TurboGears" 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/turbogears?hl=en.