response.files gets only called inside web2py_ajax.html, that is evaluated
only when you load the layout.html
in HTML, all static assets must be in the <head> to be sure all are loaded
when you try to execute some code.
If you need to include a js file and you're sure all the dependencies are
fullfilled (btw, it's not that easy.....if you include a plugin that
depends on jquery, you need to be sure that jquery is already loaded ....
have fun with it) you can use the usual <script src=> directive within your
.load view.
ATM there's no "facility" to "inject" just the files you need within
web2py: you should code your own loader, or use a third-party loader.
PS: you can use a model for your plugin that does response.files.append()
to be sure that all pages will have loaded all the files you want. The only
drawback is that those files will be loaded even if your "fragment" doesn't
get actually "inserted" within a LOAD() statement.
If you're not facing something that needs to load 300KB of different assets
for every different fragment, it's not as bad as it sounds. Given that
usually you enable client-side cache for all the /static/ files, they get
actually transmitted once.
On Tuesday, June 25, 2013 9:24:35 PM UTC+2, RHC wrote:
>
> I am trying to create a component plugin. I would like to add in some
> javascript and css files from the plugin with as little editing as possible.
>
> I have a view.load file as part of the plugin and I tried to add something
> like this to the top of this view file:
>
> {{
>
> response.files.append(URL('static','plugin_spectrum/spectrum/spectrum.css'))
> response.files.append(URL('static','plugin_spectrum/spectrum/spectrum.js'))
> response.files.append(URL('static','plugin_spectrum/plugin.js'))
> }}
>
> However, these files are not being loaded. I would like to make it as easy
> to add the component into a web page as possible using a {{=LOAD(....)}}
> command in the relevant views. It seems a bit cumbersome to have to add
> these into the relevant layout.html as well as in the specific views.
>
> Is what I am trying to do possible? If not, is there another way to load
> up the associated files along with the plugin automatically wherever the
> component is loaded into the view?
>
> Thanks,
>
> Richard.
>
--
---
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.