ERB (erb, rhtml)¶ ↑
ERB is a simple but powerful template languge for Ruby. In Tilt it’s backed by Erubi (if installed on your system] or by erb.rb (which is included in Ruby’s standard library]. This documentation applies to both implementations.
Example¶ ↑
Hello <%= world %>!
Usage¶ ↑
ERB templates support custom evaluation scopes and locals:
>> require 'erb'
>> template = Tilt.new('hello.html.erb')
>> template.render(self, :world => 'World!')
=> "Hello World!"
Or, use Tilt['erb'] directly to process strings:
template = Tilt['erb'].new { "Hello <%= world %>!" } template.render(self, :world => 'World!')
The Tilt::ERBTemplate class is registered for all files ending in .erb or .rhtml by default, but with a lower priority than ErubiTemplate. If you specifically want to use ERB, it’s recommended to use prefer:
Tilt.prefer Tilt::ERBTemplate
NOTE: It’s suggested that your program require 'erb' at load time when using this template engine within a threaded environment.
Options¶ ↑
:trim => trim¶ ↑
The ERB trim mode flags. This is a string consisting of any combination of the following characters:
-
'>'omits newlines for lines ending in> -
'<>'omits newlines for lines starting with<%and ending in%> -
'%'enables processing of lines beginning with% -
trueis an alias of<>
:outvar => '_erbout'¶ ↑
The name of the variable used to accumulate template output. This can be any valid Ruby expression but must be assignable. By default a local variable named _erbout is used.
:freeze => false¶ ↑
If set to true, will set the frozen_string_literal flag in the compiled template code, so that string literals inside the templates will be frozen.
See also¶ ↑
Related module¶ ↑
Required files
- erb