handlebars.java
handlebars.java copied to clipboard
ClassPathTemplateLoader always add .hbs as the template file extension
Hello,
I'm using ClassPathTemplateLoader
to load my template. My template are named for instance "template.json" but the path that the loader is attempted to resolve is "template.json.hbs"...
Here's an example of the code I'm using :
final TemplateLoader loader = new ClassPathTemplateLoader("template/requests/", ".json");
final Template queryTemplate = handlebars.compile(loader.resolve("my-request"));
And the file is located in classpath template/requests/my-request.json
But I'm facing the error below :
java.io.FileNotFoundException: /template/requests/my-request.json.hbs at com.github.jknack.handlebars.io.URLTemplateLoader.sourceAt(URLTemplateLoader.java:70) at com.github.jknack.handlebars.Handlebars.compile(Handlebars.java:438)
So I'm thinking about an issue, as the suffix part of the constructor is supposed to avoid adding the default extension .hbs
Regards
You should be able to just do the following
String prefix = "/template/requests/";
String suffix = ".json";
TemplateLoader templateLoader = new ClassPathTemplateLoader(prefix, suffix);
Handlebars handlebars = new Handlebars(templateLoader);
Template template = handlebars.compile("my-request");
template.apply(context);
Best of luck.
Ok I'll test that, thank you