2016-11-22 73 views
3

我正在使用春季百里香的电子邮件模板。我需要在我的模板中包含一个MS-outlook [如果mso]的检查。我需要在块内设置一个变量。我想知道是否有办法做到这一点。里面的百里香[如果mso]

<!--[if mso]><p style="line-height:0;margin:0;">&nbsp;</p><v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" th:href="@{|${baseUrl}/#/signup?email=${registrationRequest.email}&amp;key=${registrationRequest.registrationToken}|}" style="width:124px" arcsize="8%" strokecolor="#339561" filled="t"><v:fill type="gradient" angle="180" color="#44C781" color2="#3AA96E"></v:fill><v:textbox style="mso-fit-shape-to-text:t" inset="0px,11px,0px,11px"><center style="font-size:14px;line-height:24px;color:#FFFFFF;font-family:Tahoma,sans-serif;font-weight:bold;mso-line-height-rule:exactly;mso-text-raise:4px">Register</center></v:textbox></v:roundrect><![endif]--> 

回答

0

我通过[如果MSO]的整个块移动服务器侧内解决了这个问题。我附加所需的变量并呈现使用

<div th:remove="tag" th:utext="${msoTemplate}"></div> 
1

你可以提供的HTML代码整个MS Outlook中特定块,包​​括特殊的起始和结束的评论在模板中的块,通过变量,但这样做去除能力为Thymeleaf在该块内执行变量替换。

保留变量替换可以非常容易地通过使用两个变量而不是一个变量来实现:一个开始MSO注释变量和一个结束MSO注释变量 - 这些变量分别生成开始MSO和结束MSO注释。

离开展望特定代码的模板内,在开始/结束标记这样包起来:

<div th:remove="tag" th:utext="${startMsoComment}"></div> 

<!-- Outlook specific markup --> 
... variable substitution works here 
<p style="line-height:0;margin:0;">&nbsp;</p> 
<v:roundrect 
... variable substitution works here 
</v:roundrect> 
... variable substitution works here 

<div th:remove="tag" th:utext="${endMsoComment}"></div> 
0

在我看来,更好的办法有,如果MSO伪评论是个使用:阻止

<th:block th:utext="${ifgtemso9}"></th:block> 
.. your html ... 
<th:block th:utext="${endif}"></th:block> 

,当你设置你的模型或上下文,你做这样的事情:

ctxEmail.setVariable("ifgtemso9","<!--[if gte mso 9]>"); 
ctxEmail.setVariable("ifnotmso15comment","<!--[if !mso 15]><!-->"); 
ctxEmail.setVariable("endif","<!--<![endif]-->"); 
ctxEmail.setVariable("endif_end","<![endif]-->"); 

然后在utext中使用相应的变量。

(我打电话thymeleaf与上下文直接在这里,但我相信你知道你可以设置模型参数自己)