eruby - printing in erb without '<%= %>' or ruby on rails -


similar print in erb without <%=?

however, answer there specific ruby on rails. there similar capability in vanilla erb?

here's use case:

<% [     'host_perfdata_command',     'service_perfdata_command', ].each |var|     value = instance_variable_get("@#{var}")     if value         %><%= "#{var}=#{value}" %><%     end end -%> 

while works, it i%><%=s hard r%><%ead.

basically, need write directly output string. here's minimal example:

template = <<eof var 1 <% print_into_erb var1 %> var 2 <%= var2 %> eof  var1 = "the first variable" var2 = "the second one" output = nil  define_method(:print_into_erb) {|str| output << str }  erb = erb.new(template, nil, nil, 'output') result = erb.result(binding) 

but because feel obligated point out, pretty unusual need this. other answers have observed, there number of ways rewrite template in question readable without directly concating output string. how when needed.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -