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