Skip to content

Dynamic Partial (lookup) with a "default" parameter doesn't work #531

@gatim

Description

@gatim

Hi,

The last version of this project (4.0.5) with a JDK 1.7 works pretty well but I think that I have found a problem.

The following code throws an exception:
{{> (lookup myObject 'aVariable') myObject.otherObject}}

com.github.jknack.handlebars.HandlebarsException: /template/common/aTemplate.hbs:4:78: found: '}}', expected: '='
      {{> (lookup myObject 'aVariable') myObject.otherObject}}
                                      ^
    at com.github.jknack.handlebars.internal.HbsErrorReporter.syntaxError(HbsErrorReporter.java:93)
    at org.antlr.v4.runtime.ProxyErrorListener.syntaxError(ProxyErrorListener.java:65)
    at org.antlr.v4.runtime.Parser.notifyErrorListeners(Parser.java:566)
    at com.github.jknack.handlebars.internal.HbsErrorStrategy.reportInputMismatch(HbsErrorStrategy.java:186)
    at org.antlr.v4.runtime.DefaultErrorStrategy.reportError(DefaultErrorStrategy.java:148)
    at com.github.jknack.handlebars.internal.HbsParser.hash(HbsParser.java:2096)
    at com.github.jknack.handlebars.internal.HbsParser.pexpr(HbsParser.java:1764)
    at com.github.jknack.handlebars.internal.HbsParser.partial(HbsParser.java:1563)
    at com.github.jknack.handlebars.internal.HbsParser.statement(HbsParser.java:373)
    at com.github.jknack.handlebars.internal.HbsParser.body(HbsParser.java:222)
    at com.github.jknack.handlebars.internal.HbsParser.template(HbsParser.java:165)
    at com.github.jknack.handlebars.internal.HbsParserFactory$1.parse(HbsParserFactory.java:84)
    at com.github.jknack.handlebars.cache.NullTemplateCache.get(NullTemplateCache.java:54)
    at com.github.jknack.handlebars.Handlebars.compile(Handlebars.java:414)
    at com.github.jknack.handlebars.Handlebars.compile(Handlebars.java:357)
    at com.github.jknack.handlebars.Handlebars.compile(Handlebars.java:343)
    at be.smals.hfcse.emsr.kmehrvalidation.core.TemplateTest.testT(TemplateTest.java:76)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

I have tried this code in javascript and it works.

NOTE: There is a work around for this problem but the context of the called template is not changed.

You have to define a parameter explicitly:
{{> (lookup myObject 'aVariable') myParam=myObject.otherObject}}

And use it in the other template like that:
{{myParam.otherObject.otherVariable}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions