Templates¶
Templates let you generate the contents of a file from data. OpenVox supports two template languages: ERB (Embedded Ruby) and EPP (Embedded Puppet).
ERB templates¶
ERB (Embedded Ruby) templates were historically used to customize file contents
based on code. Embedded code is written in Ruby, and variables are referenced
through Ruby instance variables (@config):
# Managed by OpenVox
<% @config.each do |key, value| -%>
<%= key %>
<% value.each do |k, v| -%>
<%= k %> <%= v %>
<% end -%>
<% end -%>
EPP templates¶
EPP (Embedded Puppet) templates use roughly the same markup as ERB, but all embedded code is written in the Puppet language instead of Ruby. EPP is the recommended choice for new templates.
# Managed by OpenVox
<%- |
Hash $config
| -%>
<% $config.each |$key, $value| { -%>
<%= $key %>
<% $value.each |$k, $v| { -%>
<%= $k %> <%= $v %>
<% } -%>
<% } -%>
The EPP syntax breaks down as follows:
- Code blocks are wrapped in
<%and%>(or<%-and-%>to strip leading and trailing whitespace, respectively). - The parameter block is surrounded by
<%- |and| -%>, declaring the template's typed parameters. - Expression tags (
<%= ... %>) insert the value of a variable. - Inline comments start with
<%#.
You load and evaluate templates with the epp and template
functions, covered in the next chapter.