[email protected] wrote:
I wonder if we're looking at the wrong solution. In this case I want to include a javascript resource file such as jQuery.js so what I really want is to specify a script tag to be added to the header rather than an embedded javascript extension object content.
I suppose I could look at the jsx extension code to see how this is done as it is clearly doing this somehow?
You don't need to do that. There is a plugin that allows to include links to local JS files, which from Velocity would be called as: $xwiki.jsfx.use('/js/jquery/jquery.js'), provided that the file is located in <webapproot>/resources/js/jquery/jquery.js Now, going through velocity is an unneeded detour, since velocity code goes back to Java through parsing and reflexion. The only problem is that there is no (easy and clean) way to get hold of a reference to the plugin, since rendering is in the new, "2.0" component world, while the plugin is in the old monolithic world. I've been planning to reimplement the skin extensions as components for a while, but since it wasn't a priority, it isn't done yet. So, there are 2 solutions: 1. Make your macro depend on the xwiki-core and xwiki-plugin-skinx modules, then get a reference to the XWiki object from the execution context, then call getPlugin("jsfx") and call use("") on it. 2. Manually inject the file in the list of pulled extension, duplicating the code from AbstractSkinExtensionPlugin#getPulledResources (see http://svn.xwiki.org/svnroot/xwiki/platform/xwiki-plugins/trunk/skinx/src/ma... ) which means: from the execution context, get the xwiki context as a Map, from which you should get the value from "com.xpn.xwiki.plugin.skinx.JsSkinFileExtensionPlugin" (cast as a Set) and add "js/jquery/jquery.js" to it. -- Sergiu Dumitriu http://purl.org/net/sergiu/