Ruby eruby: Difference between revisions
From wikinotes
No edit summary |
|||
Line 14: | Line 14: | ||
</blockquote><!-- docs --> | </blockquote><!-- docs --> | ||
= Tags = | = Usage = | ||
<blockquote> | |||
<syntaxhighlight lang="ruby"> | |||
require "erb" | |||
# locals will be passed to ERB template | |||
name = "You" | |||
# create template, and render it using locals | |||
template = ERB.new("hello <%= name %>") | |||
template.resuilt(binding) | |||
</syntaxhighlight> | |||
</blockquote><!-- Usage --> | |||
= Syntax = | |||
<blockquote> | |||
== Tags == | |||
<blockquote> | <blockquote> | ||
<source lang="html4strict"> | <source lang="html4strict"> | ||
Line 35: | Line 51: | ||
</source> | </source> | ||
</blockquote><!-- tags --> | </blockquote><!-- tags --> | ||
</blockquote><!-- Syntax --> |
Revision as of 02:05, 13 May 2022
A templating engine builtin to ruby. Commonly used within ruby rails .
File extension is .erb
.
Documentation
homepage http://www.modruby.net/ text helpers (ex: simple_formT) https://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html
Usage
require "erb" # locals will be passed to ERB template name = "You" # create template, and render it using locals template = ERB.new("hello <%= name %>") template.resuilt(binding)
Syntax
Tags
<!-- comment --> <%# comment %> <!-- NOTE: no comments can escape eruby end '%>' --><!-- variable value --> <%= value %><!-- statements --> <% 5.times do %> <p>hello.</p> <% end %>