When to use "<%" vs "<%="


#1

When do you use <% vs <%=

I see both quite often and I'm not sure when to use which.

Thank you!


#2

<% you use when what you are doing shouldn't be seen by the user for example writing a loop:

<% items.each do  |item| %>
  
<% end %>

and then you use <%= if you want the use to see the things, so we loop over items here, and we want to show the items to the user so we use <%=:

<% items.each do  |item| %>
  <p><%= item %></p>
<% end %>

#3

Thanks for this! I also found another answer

<% %> executes the code between the 2 brackets.

<%= %> returns the value between the 2 brackets.

Example:

<% Response.Write("Hello.") %>

vs

<%= "Hello" %>

Source: http://stackoverflow.com/questions/2430794/what-is-the-difference-between-and


5 show a tag