Extending the Comments Component in Handlebars | Community
Skip to main content
Andras_Fejer
New Participant
October 16, 2015
Solved

Extending the Comments Component in Handlebars

  • October 16, 2015
  • 2 replies
  • 1118 views

Hello,

I'm trying to extend the comments component (resourceSuperType="social/commons/components/hbs/comments"). I want to limit the comments number to 1 per user in a comment system.
I managed to get it running and altered the HBS script to my needs, but neither can I find a HBS template property which tells me if the current user already wrote a comment, nor will the system allow me to register new HBS helpers or HBS attributes.

For the helper I tried to add a simple conditional helper. It shows up in Firebug under the Handlebars helpers, but the HBS script won't find it:
[img]handlebars helper.png[/img]

I also tried to add a custom attribute in the component's javascript found under: /libs/social/commons/components/hbs/comments/clientlibs/commentsystem.js

[img]handlebars attribute.png[/img]

My console.log output shows up in the console but the HBS script cannot find the attribute:

[img]handlebars attribute 2.png[/img]

How can you add new HBS template helpers?

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 Andras_Fejer

I learnt the solution to how to extend hbs script of the SCF components. Since the logic is processed on the server side (instead of the client side), the extended component's factory service (com.adobe.cq.social.commons.comments.api) needs to be extended in Java.

Example:

@Component(name = "My News Comment System Component Factory") @Service public classNewsCommentSystemComponentFactory extends CommentSystemSocialComponentFactory

Also the component created by the factory needs to be extended and here you can add your custom changes.

Example:

public class NewsCommentSystemComponent extends AbstractCommentCollection { ... public boolean isDisplayEmailCheckbox() { return this.hasUserCommented() || this.isCommentCreator(); } }

2 replies

JK_Kendall
New Participant
March 7, 2016

There is now documentation on Custom SCF Helpers.

- JK

Andras_Fejer
Andras_FejerAuthorAccepted solution
New Participant
October 16, 2015

I learnt the solution to how to extend hbs script of the SCF components. Since the logic is processed on the server side (instead of the client side), the extended component's factory service (com.adobe.cq.social.commons.comments.api) needs to be extended in Java.

Example:

@Component(name = "My News Comment System Component Factory") @Service public classNewsCommentSystemComponentFactory extends CommentSystemSocialComponentFactory

Also the component created by the factory needs to be extended and here you can add your custom changes.

Example:

public class NewsCommentSystemComponent extends AbstractCommentCollection { ... public boolean isDisplayEmailCheckbox() { return this.hasUserCommented() || this.isCommentCreator(); } }