If you're just worried about code organization and want the JS code in a 
separate file, you could move it to its own template and then include it 
where needed. For example, move your JS code to a file like /views/my.js. 
Then in your view:

<script>
{{include 'my.js'}}
</script>

However, that will be somewhat inefficient if you've got lots of Javascript 
code but only a little bit of dynamically generated web2py content mixed 
in. An alternative is to define the dynamically generated web2py variables 
in one block of Javascript in the template, and then load a static JS file 
that simply refers to those variables (this is how web2py_ajax.html works 
-- notice that it defines several JS variables, which are then used by 
web2py.js). So, in your view:

<script>
var someVar = '{{=T('some phrase to be translated')}}';
var someURL = '{{=URL('default', 'myfunction')}}';
</script>
<script src="{{=URL('static', 'js', 'my.js')}}"></script>

Then in my.js, you can refer to someVar and someURL.

Anthony

On Wednesday, December 23, 2015 at 12:48:03 PM UTC-5, 
luis.vallada...@metamaxzone.com wrote:
>
> Yes, inside my javascript i have a lot of web2py helpers for string 
> internationalization and even for looping between a dictionary of data and 
> generating a set of markers for google maps, also i use the web2py URL 
> helpers for the ajax requests URL. I can change the way i handle the loop 
> and the URL, but for internationalization i have not found any way to 
> handle the internationalization
>
> El miércoles, 23 de diciembre de 2015, 12:07:46 (UTC-4:30), Anthony 
> escribió:
>>
>> Are you saying some of your Javascript code is generated via web2py 
>> templates? If so, it's hard to say what the best approach would be without 
>> seeing some code.
>>
>> Anthony
>>
>> On Wednesday, December 23, 2015 at 9:46:41 AM UTC-5, 
>> luis.va...@metamaxzone.com wrote:
>>>
>>> Hello!
>>>
>>> I've been analyzing how to work around in the best form an "issue", this 
>>> doesnt affect the functionality of my code but it is against good practices.
>>>
>>> My website have a full internationalization and uses some variables 
>>> passed by the controller inside the javascript to generate a highly 
>>> dynamical page, this is no problem if i have my javascript inline my HTML 
>>> templates, but for sake of order and good practices i wish to have my .js 
>>> and .html in different files, but if i've the js outside my template it 
>>> doesnt know how to process a web2py helper instruction.
>>>
>>> So i've been thinking in some workarounds but i dont find a good 
>>> solution for now, may be some of you have a suggestion for this.
>>>
>>> Thank you very much!
>>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to