我如何将GSP呈现为字符串? [英] How can I render a GSP as a String?

查看:96
本文介绍了我如何将GSP呈现为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的电子邮件通讯,我需要为字符串呈现GSP(通讯的HTML),所以我可以将它传递给我的电子邮件方法。我在堆栈溢出中发现了很多解决方案,但我不知道哪一个最适合用于Grails 2.2(最新版本)。



那么你有什么看法?如何将GSP呈现为字符串而不呈现给HTTP响应?



感谢并致以最诚挚的问候。

Patrick

解决方案

在Grails 2.x中,一个 groovyPageRenderer 到服务中。这允许您通过其 render()方法渲染任何视图或模板。



有关更多信息,请查看Haki先生的这篇不错的帖子



另请注意,如果您使用的是邮件插件,你可以为您的电子邮件正文使用视图


For my email newsletter I need to render a GSP (the HTML for the newsletter) as a String, so I can pass it to my email method. I’ve found many solutions here on Stack Overflow, but I don't know which one would be the best to use with Grails 2.2 (the most recent version).

So what’s your opinion? How would you render a GSP as a String without rendering it to the HTTP response?

Thanks and best regards.

Patrick

解决方案

In Grails 2.x, you can inject a groovyPageRenderer into a service. This allows you to render any view or template you want via its render() method.

For more information, check out this nice post from Mr. Haki.

Also note that if you’re using the Mail plugin, you can use a view for your email body.

这篇关于我如何将GSP呈现为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆