Search code examples
javastringtemplate

Stringtemplate compare strings does not work


Can someone explain why this does not work ?

StringTemplate query = new StringTemplate("hello " +  
                "$if(param==\"val1\")$" +  
                " it works! " +  
                "$endif$ " +  
                "world");  
        query.setAttribute("param", "val1");  
        System.out.println("result: "+query.toString());  

It throws

eval tree parse error :0:0: unexpected end of subtree at org.antlr.stringtemplate.language.ActionEvaluator.ifCondition(ActionEvaluator.java:815) at org.antlr.stringtemplate.language.ConditionalExpr.write(ConditionalExpr.java:99)


Solution

  • ST doesn't allow computation in the templates. That would make it part of the model.