Adding JS library files to plone logged-in bundle with registry.xml

I thought I'd package cart.js for Plone5. Used mrbob for addon bootstrapping. Then took a look at the docs. Came up with the following registry.xml contents (also have a "cartjs" resource directory configured), to make the JS files available:

<?xml version="1.0"?>
<registry xmlns:i18n="http://xml.zope.org/namespaces/i18n" 
          i18n:domain="collective.cartjs">
  <records prefix="collective.cartjs/cartjs"
           interface='Products.CMFPlone.interfaces.IResourceRegistry'>
    <value key="js">++resource++cartjs/cart.js</value>
    <value key="js">++resource++cartjs/cart.min.js</value>
    <value key="js">++resource++cartjs/rivets-cart.js</value>
    <value key="js">++resource++cartjs/rivets-cart.min.js</value>
  </records>
</registry>

That was sufficient to publish the resources. But how do I add e.g. cart.min.js to the plone logged-in users' bundle? I tried adding to above the following (to just add all the files):

    <value key="resources">
        <element>plone-logged-in</element>
    </value>
    <value key="enabled">True</value>

But that triggered an error. Any suggestions would be appreciated.

Got it. Two mistakes:

  • the prefix has to be "plone.resources", as in:

    <records prefix="plone.resources/cartjs" ..
    
  • Silly enough, I had not realized you should have multiple <records> sections in resource.xml ... self-evident in hindsight, but might be something the docs could illustrate more explicitly.

So, this ended up working ok:

<?xml version="1.0"?>
<registry xmlns:i18n="http://xml.zope.org/namespaces/i18n" 
          i18n:domain="collective.cartjs">
  <!-- define resources; note the plone.resources prefix -->
  <records prefix="plone.resources/cartjs"
           interface='Products.CMFPlone.interfaces.IResourceRegistry'>
    <value key="js">++resource++cartjs/cart.js</value>
    <value key="js">++resource++cartjs/cart.min.js</value>
    <value key="js">++resource++cartjs/rivets-cart.js</value>
    <value key="js">++resource++cartjs/rivets-cart.min.js</value>
  </records>

  <!-- add the resources to the bundle, effectively by redefining it -->
  <records prefix="plone.resources/plone-logged-in"
                interface='Products.CMFPlone.interfaces.IBundleRegistry'>

    <!-- include existing resources by using purge=False -->
    <value key="resources" purge="false">
       <!-- add cartjs resources -->
      <element>cartjs</element>
    </value>
  </records>

</registry>

I am not quite sure, however, whether I should use the minified or non-minified files since bundling will minify them anyway...?