How add js scripts to head tag
Hi!
We are trying to integrate Exhibit to a Nuxeo application.
Unfortunately, they need to add some scripts and other things exactly to the head tag of the HTML document.
Can you, please, give some info how this can be done. We don't need this for all pages - just for a few.
Thanks!
Hi,
You have several options, some of them are only available in recent versions of Nuxeo.
If you'd like to do this just for a few pages, you can insert links in the xhtml template using a slot that was made available since 5.4.2:
<ui:define name="header_scripts">
<script type="text/javascript" src="#{baseURL}scripts/jquery/jquery.hotkeys.js"></script>
</ui:define>
See https://jira.nuxeo.com/browse/NXP-6551 for details.
When using earlier versions, you can also contribute your resources to the theme view fragments (if you'd like the scripts to be available on all pages), for instance by adding your resources to the “nuxeo5 includes” fragment used in the Nuxeo default theme:
<component name="org.nuxeo.theme.myCustomContrib">
<require>org.nuxeo.theme.nuxeo.default</require>
<extension target="org.nuxeo.theme.services.ThemeService" point="views">
<view name="nuxeo5 includes" template-engine="jsf-facelets" merge="true">
<resource>jquery.hotkeys.js</resource>
</view>
</extension>
<extension target="org.nuxeo.theme.services.ThemeService" point="resources">
<resource name="jquery.hotkeys.js">
<path>scripts/jquery/jquery.hotkeys.js</path>
</resource>
</extension>
</component>
You do not have to name the resource like the file, but keeping the extension “.js” is important.
If you only have some custom JS functions to add to all pages, you can also override the file at nuxeo.war/scripts/custom-javascript.js that is an empty placeholder in the default application.
Note that we're currently making improvements to make theme resources management more modular (see https://jira.nuxeo.com/browse/NXP-7520), so we'll probably advertise new ways of doing so from the 5.5. version (but options i gave above will be kept for compatibility).
Update since 5.5 release: see documentation available at http://doc.nuxeo.com/x/N4AO