You can append a list of JS files to response.files, and as long as your
layout.html includes web2py_ajax.html, the JS files will be loaded in the
head. For example, in a controller function that requires a particular JS
file:
response.files.append(URL('static', 'js/custom.js'))
Note, web2py_ajax.html simply calls response.include_files(), which you can
also call directly (in the layout.html head) if necessary.
See http://web2py.com/book/default/chapter/04#response.
If you need to generate parts of the JS dynamically, then it makes sense to
put the JS directly in a view so you can use the web2py template language to
fill in the dynamic parts of the JS (web2py_ajax.html does that, for
example).
Anthony
On Friday, September 30, 2011 7:07:54 PM UTC-4, monotasker wrote:
>
> From the documentation in the web2py book it seems like the standard way of
> including custom js is to place the code within the view files themselves.
> But I'd rather put all of my js in the static/js folder. In this case, do I
> need to link to each file in the header (or footer) of layout.py or is there
> a programmatic way of automatically including any files I place in that
> static/js folder?
>
> Thanks,
>
> Ian
>