Ruby eruby: Difference between revisions
From wikinotes
(→Tags) |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
A templating engine | A templating engine builtin to ruby. Commonly used within [[ruby rails]] . | ||
File extension is <code>.erb</code>. | File extension is <code>.erb</code>. | ||
Line 7: | Line 7: | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
| | | homepage || https://docs.ruby-lang.org/en/2.7.0/ERB.html | ||
|- | |- | ||
|} | |} | ||
</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 33: | Line 49: | ||
</source> | </source> | ||
</blockquote><!-- tags --> | </blockquote><!-- tags --> | ||
</blockquote><!-- Syntax --> | |||
</blockquote><!-- |
Latest revision as of 02:07, 13 May 2022
A templating engine builtin to ruby. Commonly used within ruby rails .
File extension is .erb
.
Documentation
homepage https://docs.ruby-lang.org/en/2.7.0/ERB.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 %>