我有一个play.erb文件:
<p>Welcome!<br><p>
<% if $wgplaying==true %>
Template: <%= $template %>
<% end %>
<br><br>
<% if $wginword==true && $wgplaying==true && $a!='' %>
Character <%= $a %> is in word.
<% end %>
<% if $wginword==false && $wgplaying==true && $a!='' %>
Character <%= $a %> is not in word.
<% end %>
<br><br>
我想写
"Character <%= $a %> is in word."
或
"Character <%= $a %> is not in word."
在文本文件中,但是我不知道应该使用什么命令。还是应该在Ruby文件中执行此操作?
ERB在Ruby的标准库中,所以尝试这样的事情:
require 'erb'
TEMPLATE_FILE = 'template.erb'
$wgplaying = true
$template = "This is my template"
$wginword = true
$wgplaying = true
$a = "something"
render = ERB.new(File.read(TEMPLATE_FILE),trim_mode: ">")
puts render.result
new
方法有很多选项。
这些是new
选项:
trim_mode