Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot with Handlebars: could not find helper: 'dateFormat'

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.

like image 348
AyKarsi Avatar asked Oct 18 '25 17:10

AyKarsi


1 Answers

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);
like image 137
AyKarsi Avatar answered Oct 22 '25 02:10

AyKarsi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!