0

I'm new to Ruby, and I found the <%= @my_variable %> a little lengthy and less readable. Shouldn't erb have something like ${@my_variable} (like the good old Velocity engine in Java)?

2 Answers 2

4

erb, as its name suggests, is intended for embedded ruby code. I don't think it has any other syntax beyond the following recognised tags:

<% Ruby code -- inline with output %>
<%= Ruby expression -- replace with result %>
<%# comment -- ignored -- useful in testing %>
% a line of Ruby code -- treated as <% line %> (optional -- see ERB.new)
%% replaced with % if first thing on a line and % processing is used
<%% or %%> -- replace with <% or %> respectively

If you don't like erb syntax there are other alternative template engines for Ruby. Take a look at Haml, Liquid, Mustache or Tenjin.

Sign up to request clarification or add additional context in comments.

Comments

2

I guess the answer is no according to the ERB documentation.

ERB recognizes certain tags in the provided template and converts them based on the rules below:

<% Ruby code -- inline with output %>
<%= Ruby expression -- replace with result %>
<%# comment -- ignored -- useful in testing %>
% a line of Ruby code -- treated as <% line %> (optional -- see ERB.new)
%% replaced with % if first thing on a line and % processing is used
<%% or %%> -- replace with <% or %> respectively
All other text is passed through ERB filtering unchanged.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.