-
Notifications
You must be signed in to change notification settings - Fork 53
Open
Description
The subscript syntax somevar[someprop] should do all of the things that the dot syntax somevar.someprop does plus be able to index arrays and pass in variables.
Here are a couple of scenarios where they differ
Scenario 1: referencing a property of an undefined variable.
public static void main(String[] args) {
{ // works fine
JtwigModel model = JtwigModel.newModel();
JtwigTemplate template = JtwigTemplate.inlineTemplate("{{foo.bar}}");
template.render(model);
}
{ // throws CalculationException
JtwigModel model = JtwigModel.newModel();
JtwigTemplate template = JtwigTemplate.inlineTemplate("{{foo['bar']}}");
template.render(model);
}
}Scenario 2: Referencing a bean property
public static class Foo {
private String bar = "baz";
public String getBar() {
return bar;
}
public void setBar(String bar) {
this.bar = bar;
}
}
public static void main(String[] args) {
{ // works fine
JtwigModel model = JtwigModel.newModel();
model.with("foo", new Foo());
JtwigTemplate template = JtwigTemplate.inlineTemplate("{{foo.bar}}");
template.render(model);
}
{ // throws CalculationException
JtwigModel model = JtwigModel.newModel();
model.with("foo", new Foo());
JtwigTemplate template = JtwigTemplate.inlineTemplate("{{foo['bar']}}");
template.render(model);
}
}This would make it more inline with similar templating languages
baharclerode
Metadata
Metadata
Assignees
Labels
No labels