3

I'm trying to get the handlebars dateFormat to work. At the moment I'm getting the error com.github.jknack.handlebars.HandlebarsException: /hbs/doc/docheader.hbs:6:12: could not find helper: 'dateFormat'

when I call {{dateFormat doc.documentDate format="yyyy-MM-dd"}}.

This is my relevant gradle configuration: compile 'pl.allegro.tech.boot:handlebars-spring-boot-starter:0.2.14' compile 'com.github.jknack:handlebars-helpers:4.0.6', 'com.github.jknack:handlebars-jackson2:4.0.6', 'com.github.jknack:handlebars-humanize:4.0.6', 'com.github.jknack:handlebars-markdown:4.0.6' As far as I understand the string helpers should be included in handlebars-jackson2:4.0.6.

AyKarsi
  • 9,435
  • 10
  • 54
  • 92

1 Answers1

4

Turns out that the string helpers are not registered by default. The following code made it work:

TemplateLoader loader = new ClassPathTemplateLoader("/hbs", ".hbs");
this.handlebars = new Handlebars(loader);
StringHelpers.register(this.handlebars);
AyKarsi
  • 9,435
  • 10
  • 54
  • 92
  • 1
    Where is this code placed? In a Configuration Class or Test Class? I am assuming this is Java code? Thanks. – cellepo Sep 07 '19 at 00:50