Reputation: 127
I decided to try out the .slim (slim template engine) since I don't like .erb and I also want to take the time to learn something that might prove useful in the long run.
Since I am at the same time following rails_tutorial I came to the part where yield(:title)
is used
With .erb it looks like this:
<title><%= yield(:title) %> | Ruby on Rails Tutorial Sample App</title>
With .slim I managed to make it look like:
title
=> yield(:title)
| | Ruby on Rails Tutorial Sample App
Now, what I want to do is to be able to type it in a single line. So is there a way to do that using .slim?
Here is another example I can't seem to make one line
a<> href="http://www.railstutorial.org/"
em Ruby on Rails Tutorial
Probably down the line I will not even do something like this but at this point in order to better learn I would like some pointers in regards to .slim.
The other question in order to prevent more questions like this is, where can I find a detailed documentation or tutorials with examples such as these.
FOLLOW-UP:
How would I then convert this:
<% flash.each do |message_type, message| %>
<div class="alert alert-<%= message_type %>">
<%= message%>
</div>
<% end %>
Ok I think I have understood it:
- flash.each do |message_type, message|
.alert class="alert-#{message_type}"
= message
Upvotes: 2
Views: 537
Reputation: 1462
A tag followed by text will output that text as the tag's contents. You can use string interpolation #{expression}
inside the text to output variables.
Content text with a variable interpolated:
title #{yield(:title)} | Ruby on Rails Tutorial Sample App
You can also set the tag's contents to a ruby expression by using tag =
.
title = yield(:title) + " | Ruby on Rails Tutorial Sample App"
Note that in this case this won't work if yield(:title)
returns nil
When you have nested tags, you should put them on seperate lines.
Upvotes: 2