conditional in response.files.insert()

15 views
Skip to first unread message

annet

unread,
Oct 5, 2010, 2:04:30 AM10/5/10
to web2py-users
In my custom _ajax.html file I insert css and js files that are not
needed by every view in the application, therefore I wonder whether it
is possible to use conditionals in response.files.insert(), in that
case .css and .js files are only included when they are really
needed.

This is what I have in mind:


{{
response.files.insert(0,URL(r=request,a='base',c='static',f='base/css/
reset.css'))
...
if request.function=='cardexamples':
response.files.insert(3,URL(r=request,a='base',c='static',f='base/
css/jquery.lightbox-0.5.css'))
response.files.insert(9,URL(r=request,a='base',c='static',f='base/js/
jquery.lightbox-0.5.js'))
pass
...
if request.controller=='card' or request.controller=='view':
response.files.insert(10,URL(r=request,a='base',c='static',f='base/
tiny_mce/tiny_mce.js'))
pass
for _item in response.meta or []:}}


Kind regards,

Annet.

mdipierro

unread,
Oct 5, 2010, 8:35:08 AM10/5/10
to web2py-users
yes.

annet

unread,
Oct 5, 2010, 10:57:09 AM10/5/10
to web2py-users
Massimo,

Thanks, it works! I wasn't sure about the syntax ...


Kind regards,

Annet

mdipierro

unread,
Oct 5, 2010, 11:19:37 AM10/5/10
to web2py-users
What I often do is to add the response.files.append(...) in the
controller functions that need them rather the views.

annet

unread,
Oct 5, 2010, 12:53:43 PM10/5/10
to web2py-users
Massimo,

I hadn't thought of that, I added response.files.append(..) outside
the functions in the controller.


Kind regards,

Annet.
Reply all
Reply to author
Forward
0 new messages