Plone 5.2 - Why isn't my javascript file showing up in the registry?

I'm trying to get a javascript file registered, but I can't figure out what I am doing wrong.

In my.product/src/my/product, I add a directory called 'static'.

In configure.zcml, I add:

    <plone:static
           name="my.product.resources"
           type="plone"
           directory="static"
    />

Then in the static directory, I add a js file with a simple on click statement:

jQuery(function($){
    $('#hello').click(function(e){
        alert('hello');
    }
});

Then under profiles/default, in registry.xml, I have:

<?xml version="1.0"?>
<registry>
    <records prefix="plone.resources/my.product.resources"
		interface='Products.CMFPlone.interfaces.IResourceRegistry'>
	<value key="js">++plone++static/myproduct.js</value>
    </records>
</registry>

I run quick install and it "registers" because I go to Site Setup -> Resource Registries, I see 'my.product.resources' under resources. However, when I go to overrides to check my javascript file's code (Overrides -> ++plone++static/myproduct.js), I get an error popup "error loading resource for editing".

I'm assuming I'm having difficulty pointing to the file in my package, what am I doing wrong?

I might be wrong, but I think you need

<value key="js">++plone++my.product.resources/myproduct.js</value>

Because you registered your own plone static directory under the name 'my.product.resources'

give it a try.

2 Likes

Thank you very much. I was getting confused on the js value. It works now.

Also, I was having an issue where I was getting confused why it wasn't loading unless I linked it in templates I was using. I needed to define a bundle instead.

<records prefix="plone.bundles/my.product.resources"
		 interface='Products.CMFPlone.interfaces.IBundleRegistry'>
	<value key="resources">
		<element>my.product.resources</element>
	</value>
	<value key="jscompilation">++plone++my.product.resources/mytype.js</value>
</records>
1 Like