我想做这样的事情:
require 'erb'
@var = 'test'
template = ERB.new File.new("template.erb").read
rendered = template.result(binding())
Run Code Online (Sandbox Code Playgroud)
但是如何在template.erb中使用partials?
也许蛮力呢?
header_partial = ERB.new(File.new("header_partial.erb").read).result(binding)
footer_partial = ERB.new(File.new("footer_partial.erb").read).result(binding)
template = ERB.new <<-EOF
<%= header_partial %>
Body content...
<%= footer_partial %>
EOF
puts template.result(binding)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4501 次 |
| 最近记录: |