How to register custom Handlebars Helper in AEM 6.1. Documentation seems to be wrong. | Community
Skip to main content
New Participant
November 11, 2015
Solved

How to register custom Handlebars Helper in AEM 6.1. Documentation seems to be wrong.

  • November 11, 2015
  • 9 replies
  • 2690 views

I want to write custom Handlebars helper for the server side execution.

The documentation is extremely limited (2 lines on this page):

https://docs.adobe.com/docs/en/aem/6-1/develop/communities/scf/handlebars-helpers.html#Custom SCF Helpers

"... Server-side Helpers

To implement a helper on the server-side, it is necessary to

create an implementation of the com.adobe.cq.social.handlebars.api.TemplateHelper interface
register the helper with the com.adobe.cq.social.handlebars.api.TemplateHelpersService

..."

And the TemplateHelperService methods are already deprecated in AEM 6.1.

The SCF examples that can be found do not show how to write custom server-side handlebars helper, whereas for the client side it is quite clear.

Is there any real life example on how to write the helper and much more important best practice for registering them in AEM 6.1?

Will the documentation be updated and be given more details?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by JK_Kendall

There is no need to use the TemplateHelpersService any longer.

Simply implement the TemplateHelper interface, make it an OSGi Service and install it as part of an OSGi bundle.

See updated documentation (with example) at http://docs.adobe.com/docs/en/aem/6-1/develop/communities/scf/handlebars-helpers.html#Custom SCF Helpers

Let us know if you need more information.

- JK

9 replies

JK_Kendall
New Participant
March 31, 2016

An issue, CQ-74751, has been identified that will be fixed in the release following 6.1 FP4 and 6.2 GA.

The issue has to do with a custom OSGi embedding handlebars.jar, which conflicts with the internal handlebars.jar.

You may want to open a customer care support ticket.

- JK

New Participant
March 30, 2016

Hi JK ,

We are able to register server side custom handle bar as OSGI service. When we are trying to invoke this handler using client side it's giving us exception.

"org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: /apps/hmi/components/content/social/forum/components/hbs/topic/list-item.hbs:19:14: could not find helper: 'foo-text' ".

Client Side Helper Invoking Code :

 Handlebars.registerHelper('foo-text', function(context, options) {
        if (!context) {
            return "";
        }
        return "foo-" + context;
    });

 

Do we need to call/adapt any other interface ?

 

BR

Rahul

JK_Kendall
New Participant
December 4, 2015

Hi,

I wanted to let you know that the problem with registering a custom helper has been reproduced and will be investigated.

- JK

shiffalig2391
New Participant
December 2, 2015

Hi JK Kendall,

As given in the documentation, i have created FooTextHelper class that implements TemplateHelper. When i tried to use this helper in a script, it is throwing an exception i.e

this helper is not registered.

Do we need to explicitly register this helper??

JK_Kendall
New Participant
December 2, 2015

Hi Shiffali,

I asked whether it's required to create both client-side and server-side helpers and the answer was 'no'.

However, what was said was if you try to execute a template that uses the custom helper in an environment (server/client) where the helper is not available, then you would run into exceptions.

You would need to provide more details if this isn't helpful.

- JK

shiffalig2391
New Participant
December 1, 2015

HI JK Kendall,

I have tried creating a custom server-side handlebar Helper. But its not working.

Getting this exception:java.io.IOException: Trying to use unregistered helper.

As you have mentioned that there is no need to register the helper then what to do in this case.

shiffalig2391
New Participant
December 1, 2015

Hi sinners97099773,

Is it working for you? I tried it but not working for me..

New Participant
November 30, 2015

Thanks for updating the docs!

JK_Kendall
JK_KendallAccepted solution
New Participant
November 11, 2015

There is no need to use the TemplateHelpersService any longer.

Simply implement the TemplateHelper interface, make it an OSGi Service and install it as part of an OSGi bundle.

See updated documentation (with example) at http://docs.adobe.com/docs/en/aem/6-1/develop/communities/scf/handlebars-helpers.html#Custom SCF Helpers

Let us know if you need more information.

- JK