I have some trivial markup that looks like the following:
<li class="someclass">
<=% t'model.attr' %>
</li>
Is there a trivial way to comment that out? Just wrapping <!-- -->
around the block will still leave the ruby code available to the template. This means I have to comment out the HTML and Ruby specific code separately.
What's the best way to comment out all three lines with the least amount of markup?
erb is by definition "embedded ruby", you can embed every ruby code between: <%= and the other: %> , typically all written in one line. In addition, ruby one-line comments start always with # , so the <%=# Comment %> style matches perfectly with both pure-ruby and erb styles for one-line comments.
The Ruby single-line comment begins with the # character and ends at the end of the line. Any characters from the # character to the end of the line are completely ignored by the Ruby interpreter. The # character doesn't necessarily have to occur at the beginning of the line; it can occur anywhere.
An ERB template looks like a plain-text document interspersed with tags containing Ruby code. When evaluated, this tagged code can modify text in the template. Puppet passes data to templates via special objects and variables, which you can use in the tagged Ruby code to control the templates' output.
ERB stands for Embedded Ruby.
=begin
and =end
are the Ruby version of block comments.
Using them in an erb template:
<%
=begin
%>
<li class="someclass">
<=% t'model.attr' %>
</li>
<%
=end
%>
You can comment ERB blocks using #
:
<!-- <li class="someclass"> -->
<%#= t'model.attr' %>
<!-- </li> -->
or avoid the literal HTML using Rails content_tag
method:
<%#= content_tag :li, t'model.attr', :class=>:someclass %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With