将模板呈现为字符串? [英] Render a template into a string?

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

问题描述

是否可以将模板渲染为一个字符串?我想使用一个模板,并填写一些值,然后我必须保存到本地光盘。

渲染方法总是将模板发送到客户端。我想要类似的东西来运行模板,但将模板的输出保存到本地字符串变量中,我可以将其存储在本地文件系统中。

  def myTemplateString = g.render(template:test,model :[foo:bar])


Is it possible to "render" a template into a string? I would like to use a template and fill that with some values that I then must save to the local disc.

The render method always send the template to the client. I want something similar to run a template but save the output from the template to a local string variable that I can store in the local file system.

解决方案

It is simpler than you think:

def myTemplateString = g.render(template: "test", model: [foo: bar])

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

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