Insert inline styles in the middle of a Freemarker message

社会主义新天地 提交于 2020-01-06 19:42:09

问题


I'm using Freemarker to template emails being sent out to notify users of new messages. What I'd like to do is be able to display a message with this formatting and emphasis:

"Hello User 1! You've received a new message Message Title from User 2"

To do this I'm splitting the message up into two bits, then putting the Message Title in a span in the middle with font-style: italic, like so:

${message("MsgNotificationEmail.receivedNewMsg1"), recipientName}
<span style="font-style:italic;">${msgTitle}</span>
${message("MsgNotificationEmail.receivedNewMsg2", senderName)}

Is there a neater way to apply styles in the middle of a message without needing to break it up like this?


回答1:


In a typical application of FreeMarker it would look like this:

Hello ${recipientName}!
You've received a new message <span style="font-style:italic;">${msgTitle}</span>
from ${senderName}

That is, you don't have receivedNewMsg1 plus receivedNewMsg2 plus a template, just a single template.



来源:https://stackoverflow.com/questions/7791715/insert-inline-styles-in-the-middle-of-a-freemarker-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!