활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.
활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.
Hi,
I have an email template in etc/notifications folder which is of type html. I am trying to hide an element based on variable i fetch from email service params(of email service).
Below is my template code
From: ${senderEmailAddress}
Subject:${subject}
<hr>
<b>Vous êtes ?</b> ${role}
<b>Vous êtes ?</b> ${subrole}
<b>Choisissez votre profession</b> ${profession}
<b>Nom de l'entreprise</b> ${enterpriseName}
<b>Adresse</b> ${address}
<b>Nom</b> ${Name}
<b>Prénom</b> ${firstName}
<b>Téléphone</b> ${telephone}
<b>Email</b> ${email}
<b>Code postal</b> ${postalCode}
<b>Ville</b> ${ville}
<b>Pays</b> ${country}
<b>Objet de la demande</b> ${objectOfDemand}
<b>Type de produits</b> ${typeOfProducts}
<b>Veuillez saisir la référence du ou des produits concernés</b> ${reference}
<b>Saisissez votre demande</b> ${info}
<b>Produit(s) sous garantie</b> ${warranty}
<b>En cochant cette case, vous acceptez de recevoir des informations commerciales de la part de Jacob Delafon pour des produits ou des services analogues à ceux que vous avez consultés.</b> ${subscription}
<hr>
Now I want to hide '<b>' tag if ${something} is null or empty. Please suggest Arun Patidar antoniom54959291 Jörg Hoh smacdonald2008 kautuksahni
해결되었습니다! 솔루션으로 이동.
private String getSubstitutedString(Map<String, String> valueMap, String beforeParsing) {
VelocityEngine ve = new VelocityEngine();
ve.init();
VelocityContext context = new VelocityContext();
StringWriter writer = new StringWriter();
for (Map.Entry<String, String> entry : valueMap.entrySet()) {
String value = xssApi.filterHTML(entry.getValue());
value = Jsoup.parse(value).text();
context.put(entry.getKey(), value);
}
ve.evaluate(context, writer, "VelocityParser", beforeParsing);
return writer.toString();
}
Here, the argument beforeParsing is the velocity syntax template String that contains condition based variables and its values will be replaced by actual values which are in Map.
You can use the Apache Velocity templating engine to add condition based Text in Email.
We had the same requirement once and utilised Apache Velocity Templating engine and it's quite nice.
As mentioned by Himanshu/Arun, this is not supported OOB but you can still use any template engine (client/server side) like Velocity/Handlebars/Mustache etc. and get the results. You may also try for a PostProcessor if your use case requires it.
can you provide sample code of what you did
조회 수
답글
좋아요 수
private String getSubstitutedString(Map<String, String> valueMap, String beforeParsing) {
VelocityEngine ve = new VelocityEngine();
ve.init();
VelocityContext context = new VelocityContext();
StringWriter writer = new StringWriter();
for (Map.Entry<String, String> entry : valueMap.entrySet()) {
String value = xssApi.filterHTML(entry.getValue());
value = Jsoup.parse(value).text();
context.put(entry.getKey(), value);
}
ve.evaluate(context, writer, "VelocityParser", beforeParsing);
return writer.toString();
}
Here, the argument beforeParsing is the velocity syntax template String that contains condition based variables and its values will be replaced by actual values which are in Map.