I have email template .vm which contains msg with message key from messages_en.properties:
#msg("email-body")
messages_en.properties has:
email-body = Hello, $name!
After:
private String buildMessage(String templateName, Properties properties, Locale locale) {
Template template = getVelocityEngine().getTemplate(templateName);
VelocityContext context = new VelocityContext();
for (String key : properties.stringPropertyNames()) {
context.put(key, properties.getProperty(key));
}
context.put(LocaleDirective.MESSAGES_LOCALE, locale);
StringWriter writer = new StringWriter();
template.merge(context, writer);
return writer.toString();
}
I get:
Hello, $name!
And name isn't replaced with actual value.
What's the best way to manage phrases in email template? I want to put only message key in the template, not the whole phrase with placeholder.
Use evaluate directive for substitute variable inside of other variable:
Output: