Generic Script Provider Mechanism for Modular Javascript Development

The 4.0 version of the platform ships with a new sub-system allowing plugins to “provide” new scripts and css files to areas of the platform. This is now the preferred way of implementing Javascript based plugins for content area, replacing existing undocumented systems.

Providing New Scripts

Scirpts and CSS are provided through tags in the plugin.xml file of your plugin. Below is a declaration registering a script and css file to be loaded in the User Console:

 
  <external-resources>
    <file context="mantle">content/my-plugin/resources/plugins/mantle_script.js</file>
    <file context="mantle">content/my-plugin/resources/plugins/mantle_styles.css</file>
  </external-resources>

The User Console is the only non-plugin area of the platform that participates in this system. You’ll note that it’s context name is “mantle”. For plugins the name of the context should be the id of the plugin.

How to receive provided scripts

Similar to the Theme System, provided Scripts and CSS are injected automatically into web-pages by including the webcontext.js script tag in the head of the page:

 
  <script language="javascript" type="text/javascript" src="webcontext.js?context=my-plugin"></script>