Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在grails messages.properties中使用HTML发送邮件_Html_Grails_Internationalization_View_Decode - Fatal编程技术网

如何在grails messages.properties中使用HTML发送邮件

如何在grails messages.properties中使用HTML发送邮件,html,grails,internationalization,view,decode,Html,Grails,Internationalization,View,Decode,在grails中,我使用GSP模板呈现随邮件插件发送的HTML电子邮件。这可以很好地工作,但是GSP模板使用了一个param,该param又从my messages.properties文件中检索。现在我想在messages.properties中使用HTML,例如,但它在邮件中显示为文本,标记不会被解释 我已经尝试在GSP中的参数上使用.decodeHTML(),但没有成功 我必须在哪里编码/解码,或者是否可以在messages.properties中使用HTML标记 <%@ page

在grails中,我使用GSP模板呈现随邮件插件发送的HTML电子邮件。这可以很好地工作,但是GSP模板使用了一个param,该param又从my messages.properties文件中检索。现在我想在messages.properties中使用HTML,例如

,但它在邮件中显示为文本,标记不会被解释

我已经尝试在GSP中的参数上使用.decodeHTML(),但没有成功

我必须在哪里编码/解码,或者是否可以在messages.properties中使用HTML标记

<%@ page contentType="text/html"%>
<html>
<body>
${variableWithHTMLTextFromMessagesProperties}
</body>
</html>

${variableWithHTMLTextFromMessagesProperties}
来自:


用户${user.name}的配置文件是:
来自:


用户${user.name}的配置文件是:

您不能使用消息标签在GSP中进行本地化,类似于以下内容吗?控制器-

sendMail {
    to "my@email.com"
    subject "cheese"
    html g.render(template:"myTemplate")
}
然后在您的_myTemplate.gsp中-

<%@ page contentType="text/html" %>
<html><head></head>
<body>
    <p>test: <g:message code="a.test"/></p>
</body>
</html>

测试:

然后在messages.properties中-

a.test=this <br/><br/> is a test
a.test=这是一个测试

这种方式对我来说很好(Grails1.3.1,mail 0.9),我收到的html电子邮件中有两个换行符。有什么原因不能这样做吗?

您不能使用消息标签在GSP中进行本地化,类似于以下内容吗?控制器-

sendMail {
    to "my@email.com"
    subject "cheese"
    html g.render(template:"myTemplate")
}
然后在您的_myTemplate.gsp中-

<%@ page contentType="text/html" %>
<html><head></head>
<body>
    <p>test: <g:message code="a.test"/></p>
</body>
</html>

测试:

然后在messages.properties中-

a.test=this <br/><br/> is a test
a.test=这是一个测试

这种方式对我来说很好(Grails1.3.1,mail 0.9),我收到的html电子邮件中有两个换行符。有什么原因不能这样做吗?

找到了解决方案。最简单的方法就是使用
而不是
${variablewithhtmltextfromessproperties}
。这将停止HTML转义。

找到了解决方案。最简单的方法就是使用
而不是
${variablewithhtmltextfromessproperties}
。这将停止HTML转义。

我用一个自定义标记库创建了自己的解决方案

def htmlMessage = { attrs, body ->
    out << g.message(attrs, body).decodeHTML()
}
def htmlMessage={attrs,body->

out我用一个定制的taglib创建了自己的解决方案

def htmlMessage = { attrs, body ->
    out << g.message(attrs, body).decodeHTML()
}
def htmlMessage={attrs,body->

您是否可以发布GSP?您是否在GSP模板的消息标签中使用了encodeAs属性?您是否可以发布GSP?您是否在GSP模板的消息标签中使用了encodeAs属性?这是一个错误的方向;现在messages.properties中的
显示为br/这是一个错误的方向;现在messages.properties中的
显示为br/实际上,在我的例子中,messages.properties中的文本事先保存为持久化类中的字符串,然后将其传递给视图。当然,理论上我可以存储消息代码,但是我还需要存储以后应该使用的参数,所以我更倾向于直接存储消息…但我想如果你的解决方案不起任何作用,我会使用你的解决方案作为备用解决方案,所以谢谢你!实际上在我的例子中,messages.properties中的文本事先保存为持久类中的字符串,然后传递给视图。当然,理论上我可以存储改为使用消息代码,但是我还需要存储以后应该使用的参数,所以我更愿意直接存储消息…但是我想如果你的解决方案不能以任何其他方式工作,我会使用你的解决方案作为备用解决方案,所以谢谢你!