Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Add HBS Custom Helper

schmidtkevina
Level 1
Level 1
I am trying to register a new HBS helper in /etc/clientlibs/social/commons/scf/helpers.js  I have the helper in the JS but it can't find it, is there an additional step that needs to be take here to have the helper recognized?  I'm merely trying to add a modified equals helper to the SCF helpers.
 
Or, do I have to create a custom helper as outline here?
 
https://docs.adobe.com/docs/en/aem/6-2/develop/communities/scf/handlebars-helpers.html#Client-side Custom Helpers
 
I'd rather not if I don't have to because I've been having serious issues with client libs in Communities.
7 Replies
JK_Kendall
Level 8
Level 8

What release of Communities do you have?  For AEM 6.2, you need at least FP1.

I would recommend figuring out what is the issue you're having with client libs.

If you edit /etc/clientlibs/social/commons/scf/helpers.js, it could be overwritten in a future release.

The more details you could provide, the better.

- JK

schmidtkevina
Level 1
Level 1

JK Kendall wrote...

What release of Communities do you have?  For AEM 6.2, you need at least FP1.

I would recommend figuring out what is the issue you're having with client libs.

If you edit /etc/clientlibs/social/commons/scf/helpers.js, it could be overwritten in a future release.

The more details you could provide, the better.

- JK

 

We have a buddy drop from Adobe.  I added a helper in the helpers.js called equalsNuts and it doesn't recognize it.  That's the only change I made.  Is there something else that needs to be done to register the helper other than just adding it to the JS file. I get the following error.

 

/apps/social/console/components/hbs/sitepage/sitepage.hbs:14:26: org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: /libs/social/console/components/hbs/singlecolumncontent/singlecolumncontent.hbs:5:14: org.apache.sling.api.scripting.ScriptEvaluationException: org.apache.sling.scripting.sightly.SightlyException: org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: java.lang.IllegalArgumentException: could not find helper: 'equalsNuts' /libs/social/console/components/hbs/singlecolumncontent/singlecolumncontent.hbs:5:14 /apps/social/console/components/hbs/sitepage/sitepage.hbs:14:26

Cannot serve request to /content/sites/adls-resources/en/discussions.html on this server


ApacheSling/2.4 (jetty/9.2.14.v20151106, Java HotSpot(TM) 64-Bit Server VM 1.8.0_73, Mac OS X 10.11.6 x86_64)
schmidtkevina
Level 1
Level 1

This is what I added, basically a copy of equals and changed the name, this is for a POC so it's ok the modify the helpers.js directly.

 

Handlebars.registerHelper("equalsNuts", function(lvalue, rvalue, options) {
        if (arguments.length < 3)
            throw new Error("Handlebars Helper equal needs 2 parameters");
        if (lvalue != rvalue) {
            return options.inverse(this);
        } else {
            return options.fn(this);
        }
    });

schmidtkevina
Level 1
Level 1

Ok, so when do you know if you need to register it server side or not?

 

"While not required, it is recommended that custom helpers be implemented on the server-side as well as the client-side.  For SCF, most templates are compiled and rendered on the server-side as the server generates the HTML for a given component when the page is requested."

schmidtkevina
Level 1
Level 1

One other question, if I create a custom handlebars helper, does it need to be created server side as well in an OSGi bundle or will client side only suffice?

JK_Kendall
Level 8
Level 8

schmidtkevina wrote...

One other question, if I create a custom handlebars helper, does it need to be created server side as well in an OSGi bundle or will client side only suffice?

 

Yes, the documentation has been corrected.  It now reads :

"Custom helpers must be implemented on the server-side as well as the client-side, especially when passing data.  For SCF, most templates are compiled and rendered on the server-side as the server generates the HTML for a given component when the page is requested."

- JK