maxwolf929
maxwolf929

Reputation: 55

Passing if result to erb view in Sinatra

I'm trying to pass the result of (if ... else) to .erb file for example

if @p
 "show something"
else    
 "show other thing"
end

How could I do it? Thanks

Upvotes: 0

Views: 326

Answers (1)

matt
matt

Reputation: 79743

The usual way of passing values to the view in Sinatra is by using instance variables. Any instance variable you set in your route will be available in the view. So in this case you could do something like this:

@my_variable = if @p
 "show something"
else    
 "show other thing"
end

and then in your Erb view:

<%= @my_variable %>

The result will be that either show something or show other thing will appear in the rendered page depending on the value of @p.

Upvotes: 1

Related Questions