【问题标题】:Thymeleaf inside [if mso]里面的百里香叶 [if mso]
【发布时间】:2017-04-05 16:35:23
【问题描述】:

我正在使用 spring thymeleaf 制作电子邮件模板。我需要在我的模板中包含对 MS-outlook [if 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]-->

【问题讨论】:

    标签: java css spring thymeleaf


    【解决方案1】:

    我认为拥有 if mso 伪 cmets 的更好方法是使用 th:block

    <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,但我相信你知道如何自己设置模型参数)

    【讨论】:

      【解决方案2】:

      您可以通过变量提供整个 MS Outlook 特定的 HTML 代码块,包括特殊的开始和结束 cmets,但这样做会消除 Thymeleaf 在该块内执行变量替换的能力。

      通过使用两个变量而不是一个变量可以很容易地实现保留变量替换:一个起始 MSO 注释变量和一个结束 MSO 注释变量 - 它们分别只生成起始 MSO 和结束 MSO cmets。

      将 Outlook 特定代码留在模板中,并将其包装在开始/结束标记中,如下所示:

      <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>  
      

      【讨论】:

        【解决方案3】:

        我通过在服务器端移动整个 [if mso] 块解决了这个问题。我附加了所需的变量并使用

        在模板中呈现了块
        <div th:remove="tag" th:utext="${msoTemplate}"></div>   
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-01-04
          • 2016-08-14
          • 2015-11-29
          • 1970-01-01
          • 2015-12-09
          • 2018-07-08
          • 1970-01-01
          相关资源
          最近更新 更多