Configure Java HBS to find the location of some templates

In short, Java HBS (jkack. Handlebars) is looking for some templates in a directory completely different from the parent template Does anyone know how to configure jkack Handlebars where to find some templates?

I need to avoid: createlayeredhtml error com. github. jknack. handlebars. HandlebarsException:/com/XXX/YYY/ inline@53ce2ca5.hbs : 598:8: unable to find part '/ COM / xxx / YYY / template templates / carouselheader hbs’

This is the parent template:

<div data-module="{{type}}" data-module-id="{{module_id}}" class="slick-module athena-item-page-carousel">

{{> temp-templates/CarouselHeader}}

<div class="js-carousel-n-up carousel carousel-narrow carousel-banner carousel-n-up-responsive">
    {{> temp-templates/CarouselFirstTile}}

Update: I should say that the default location HBS is looking for is my (forgive me if this is not the correct term) home directory of my package in Java It is found in / SRC / main / Java / COM / company / project Is there any way to point it to something like / SRC / main / resources?

This is a complete error:

[ERROR] 2015-09-18 17:23:34.688 [main] 
Error in createLayeredHtml..
    com.github.jknack.handlebars.HandlebarsException: /com/XXX/YYY/inline@53ce2ca5.hbs:598:8: The partial '/com/XXX/YYY/temp-templates/CarouselHeader.hbs' Could not be found
        at com.github.jknack.handlebars.internal.Partial.merge(Partial.java:142)
        at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:128)
        at com.github.jknack.handlebars.internal.TemplateList.merge(TemplateList.java:61)
        at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:128)
        at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:115)
        at com.github.jknack.handlebars.Options.apply(Options.java:271)
        at com.github.jknack.handlebars.Options.fn(Options.java:237)
        at com.github.jknack.handlebars.Options.fn(Options.java:226)
        at com.github.jknack.handlebars.helper.IfHelper.apply(IfHelper.java:51)
        at com.github.jknack.handlebars.internal.Block.merge(Block.java:160)
        at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:128)
        at com.github.jknack.handlebars.internal.TemplateList.merge(TemplateList.java:61)
        at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:128)
        at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:115)
        at com.github.jknack.handlebars.internal.ForwardingTemplate.apply(ForwardingTemplate.java:82)
        at com.github.jknack.handlebars.internal.ForwardingTemplate.apply(ForwardingTemplate.java:60)
        at com.XXX.YYY.utils.HandlebarUtils.render(HandlebarUtils.java:80)
        at com.XXX.YYY.AthenaLayeredAsset.createLayeredHtml(AthenaLayeredAsset.java:68)
        at com.XXX.YYY.AthenaSlickCarousel.generateNarrowCarouselHTML(AthenaSlickCarousel.java:27)
        at com.XXX.YYY.TestAthenaLayeredAsset.testNarrowCarouselSimple(TestAthenaLayeredAsset.java:387)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
        at org.testng.TestRunner.privateRun(TestRunner.java:767)
        at org.testng.TestRunner.run(TestRunner.java:617)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
        at org.testng.SuiteRunner.run(SuiteRunner.java:240)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
        at org.testng.TestNG.run(TestNG.java:1057)
        at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
        at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
        at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
        at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:125)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

Solution

Basically, you need to make sure that your template is in your classpath and that the templateloader knows where your "part" is

After removing this error a long time ago, I finally figured out how to ensure that the directory containing all templates is included in the classpath I believe there is more than one way to do this, and Maven experts may know a better way, but I have used:

http://maven.apache.org/surefire/maven-surefire-plugin/examples/configuring-classpath.html

Then, to ensure that your templateloader knows where your "parts" are, you can use setprefix

https://github.com/jknack/handlebars.java

Or the version we use has an option in the constructor:

Protected static final templateloader = new classpathtemplateloader ("/ parts /");

Thank you very much for Roman and Tassos bassoukos tips!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>