Serving a Template through JSON

2 views
Skip to first unread message

percious

unread,
Oct 26, 2006, 10:58:14 AM10/26/06
to TurboGears
Hey guys. I have an application that has a series of selectors, which
serves up a page inside a div when certain things are selected. I am
trying to have the page served as a Kid template through turbogears so
I can forgo all the TABLE(null, mapping ...) Blahh blah... Javascript.

I figured out that loadJSONDoc() can accept a string from turbogears
and will display it properly in the div, but when I try having
turbogears return a filled in template, I get no results in the div.

Here are some snippets of code:

javascript that runs when someone clicks an item:

function requestAvailableParameters(option) {
str = getForm()
var s = "availableParameters"+str
var d = loadJSONDoc(s);
d.addCallback(showAvailableParameters);
}

function showAvailableParameters(result) {
currentPageList = result
var v = document.getElementById('availableParameters')
v.innerHTML = currentPageList
}

The name of the page is "availableParameters", getForm simply
determines which checkboxes are active on the page.


Here is my turbogears code:

@expose(template="turbolink.templates.extractor.availableParameters")
def availableParameters(self, **kw):
return dict()

and availableParameters.kid:
<html xmlns="http://www.w3.org/1999/xhtml">
Hi mom!
</html>

Any info would be usefull.

-percious

percious

unread,
Oct 26, 2006, 11:28:49 AM10/26/06
to TurboGears
Ok, I dug into MochiKit and figured it out. TG code stays the same,
kid template unchaged. Here is the new JS:

function requestAvailableParameters(option) {
str = getForm()
var s = "availableParameters"+str
var d = doSimpleXMLHttpRequest(s);
d.addCallback(showAvailableParameters);
}

function showAvailableParameters(result) {


var v = document.getElementById('availableParameters')

v.innerHTML = result.responseText
}


Personally, I feel this is a MUCH easier way of manipulating AJAX
objects because you are using templates and the normal tubogears stuff
instead of messing around with JSON. Don't know how y'all feel about
it, but I am interested in your response.

-chris

isaac

unread,
Oct 26, 2006, 12:48:44 PM10/26/06
to turbo...@googlegroups.com
On 10/26/06, percious <christoph...@pw.utc.com> wrote:
> Personally, I feel this is a MUCH easier way of manipulating AJAX
> objects because you are using templates and the normal tubogears stuff
> instead of messing around with JSON. Don't know how y'all feel about
> it, but I am interested in your response.
>
> -chris

I suggest reading this:
Hijax http://domscripting.com/blog/display/41

It's quite a good strategy for using ajax, etc.

Julio Oña

unread,
Oct 26, 2006, 2:34:39 PM10/26/06
to turbo...@googlegroups.com
Hi,

Maybe a better solution is to make a filter based on HTMLtoMochikidDOM, and have the exposed functions returning html/mochikitDOM so Hijax is easy developed on Turbogears.

http://developer.spikesource.com/wiki/index.php/HTMLtoMochiDOM_HTML_to_MochiDOM_script

regards.

percious

unread,
Oct 27, 2006, 4:25:07 PM10/27/06
to TurboGears
Yeah, you know, HTML->DOM is great, but I really want to take advantage
of the widget's "display()" method. It is pretty unclear how to do
that with JSON without re-writing all the stuff that goes into the
"display()" method on the server side. Just fuel for thought.

-chris

Reply all
Reply to author
Forward
0 new messages