Duh, had a typo in the code I sent. std.tg_js points to TG's js  
static drectory, so Mochikit lives at ${std.tg_js}/Mochikit.js. (not $ 
{std.tg_js}/js/Mochikit.js)

The "std" variable is sent to every template by TG, you don't need to  
explicitly set it, just access it from the template and you're done.

BTW, IIRC "std" has been deprecated in favor of "tg", so it should be  
${tg.tg_js}.

Hope it makes things a little bit clearer,

Alberto

On Jun 17, 2006, at 4:58 AM, Arnold wrote:

>
> Thank you Alberto,
> My problem is to set the std.tg_js variable.
> I am new in Python/Turbogears and I don't understand how to write the
> code to set the value of this variable.
>
> I import the view module in the controllers file like this:
>
> import turbogears
> from turbogears import controllers
> from turbogears import view
>
> std.tg_js="static/javascript"
>
> class Root(controllers.Root):
>       @turbogears.expose(html="newgears.templates.welcome")
>       def index(self):
>               return dict()
>
> This doesn't work, I get the message : NameError: name 'std' is not
> defined
> I also tried "view.tg_js="static/javascript" which is accepted at
> compile time but generates an error at  run time.
>
> Do you know what is already set by default in Turbogears and what I
> should  set by myself ?
>
> Thanks for your help
> Arnold
>
> I had a look at the stdvars documentation, but
>
> Alberto Valverde wrote:
>> On 11/06/2006, at 18:04, Arnold wrote:
>>
>>>
>>> Dear All,
>>> I have not found how to set up std.tg_js variable
>>> I suppose it shall be set to the path where is located the MochiKit
>>> library (relative to the project root directory) (<script
>>> src="${std.tg_js}/MochiKit.js"/>)
>>> May be I am missunderstanding something ??
>>
>> std.tg_js points to the turbogears static files directory which is at
>> turbogears/static. Mochikit.js lives in turbogears/static/js/
>> Mochikit.js so you should write.
>>
>> <script src="${std.tg_js}/js/MochiKit.js"/>
>>
>> Alternatively, if you need mochi in all pages, you can set the config
>> variable tg.mochikit_all to True so it gets automatically included in
>> all pages.
>>
>> Another way would be to return the mochikit JSLink widget in the dict
>> you return from your controller to the template engine:
>>
>> from turbogears.widgets import mochikit
>>
>> def controllermethod(....)
>>      return dict(
>>              foo = bar,
>>              mochi = mochikit,
>>      )
>>
>> This last trick takes advantage of the machinery TG widgets use to
>> pull all their required JS and CSS links into the template, it's the
>> preferred method IMO as if, by any chance, mochikit's js file path
>> changes inside TG, you won't need to update your code.
>>
>>
>> HTH,
>> Alberto
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to