Templates

From Wiki
Jump to: navigation, search

Syntax check a template.

erb -P -x -T '-' mytemplate.erb | ruby -c

Template test script.

#!/usr/bin/ruby
require 'erb'

#Test Variables
@names = ['foo', 'bar', 'baz']

temp = File.open("template.txt.erb", "rb").read;
renderer = ERB.new(temp, nil, '-')

puts output = renderer.result()

Template:

names: <%= @names.join(',') %>