Java: Passing multiple values to handlebar template

1.5k Views Asked by At

I am using handlebar templates to prepare email content dynamically before sending over it.

It's straightforward to pass just one value. For example:

What's up {{this}} template workes fine with template.apply(firstName).

Tried changing the template to What's up {{this}}, {{this}} and try to fill in by template.apply(lastName); and template.apply(firstName);.

But it doesn't work.

2

There are 2 best solutions below

2
On

You have to refer to the variables you set on the this object by their name.

What's up {{firstName}}, {{lastName}}
0
On

pass a map as parameter.

template.hbs

What's up {{firstName}}, {{lastName}}

controll.java

template.apply(new HashMap<String, Object>() {
    {
        put("firstName", "Himanshu");
        put("lastName", "Yadav");
    }
});