mut*_*ity 1 ruby views ruby-on-rails erb sinatra
在Rails中我可以使用:
x = ActionController::Base.new.render_to_string(
template: "my_module/my_view_template",
locals: { my_var: in_my_var})
Run Code Online (Sandbox Code Playgroud)
这会将视图模板结果加载到Rails中的变量.我怎样才能在Sinatra做到这一点?
我对任何模板语言持开放态度,但我更喜欢Erubis.
小智 5
Sinatra模板文档:链接
erb是一个返回字符串的函数.您可以将其分配给变量
get '/' do
template_output = erb :template
"Here is the output from template: #{template_output}"
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
248 次 |
| 最近记录: |