Hi Diez,
I followed your suggestion and was able to inect jquery_js to my
controller. However, I am running into a problem. Below is the
sample code. I expect to see the time (id=timetest) to be updated
everytime I click on "get time" link; however, it does not. Hope you
can shed a light on it. Thanks much in advance. -tpn
>From my controller (root.py):
=====================
@expose('helloworld.templates.about')
def about(self, **kw):
import time
jquery_js.inject()
return dict(now=time.ctime())
@expose()
def time(self):
import time
return dict(now=time.ctime())
>From my template:
==============
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="master.html" />
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type"
py:replace="''"/>
<title>Learning TurboGears 2.0: Quick guide to the Quickstart pages.</title>
<script type="text/javascript">
$(document).ready(function(){
$('a').click(function(event){
$('#timetest').load("/time")
});
});
</script>
</head>
<body>
<div id="timelink"><a href = "#">get time</a></div>
<div id="timetest" py:replace="now"></div>
</body>
</html>
On Sun, Nov 22, 2009 at 11:49 PM, Diez B. Roggisch <[email protected]> wrote:
> Thang Nguyen schrieb:
>> Hi,
>>
>> I added the line below into app_cfg.py for enabling Mochikit, but kept
>> on getting error.
>>
>> This is the new line added to app_cfg.py:
>>
>> tg.include_widgets = ['turbogears.mochikit']
>>
>> The error I got:
>> from helloworld.config.app_cfg import base_config
>> File "C:\turbogears\sandbox\HelloWorld\helloworld\config\app_cfg.py", line
>> 66,
>> in <module>
>> tg.include_widgets = ['turbogears.mochikit']
>> NameError: name 'tg' is not defined
>
> This is only worknig in TG1.
>
> There is no direct equivalent for this in TG2.
>
> First of all, you need to install tw.mochikit. Then the normal procedure
> is to write a ToscaWidget that declares a dependency to that widget.
>
> As a result, the tw.mochikit will be automatically injected into the page.
>
> Alternatively, you can call .inject() on the respective widget youself.
> I don't use tw.mochikit, but for e.g. jquery, this works roughly like this:
>
>
> from tw.jquery import jquery_js
>
>
> class MyController(...):
>
>
> �...@expose(...)
> def action(self):
> jquery_js.inject()
> ...
>
>
>
> If you are a 100% sure you want MK with *every* page, then you should
> consider placing the inject into your BaseController.__call__.
>
> 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=.
>
>
>
--
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.