March 2025
Intermediate to advanced
472 pages
12h 10m
English
Slim is a templating language that can replace ERB.[126] It’s designed to require much less code to achieve the same results, and it does this by using a nested structure instead of HTML tags. Consider this ERB:
| | <h2><%= t('.title') %></h2> |
| | <table> |
| | <%= render(cart.line_items) %> |
| | |
| | <tr class="total_line"> |
| | <td colspan="2">Total</td> |
| | <td class="total_cell"><%= number_to_currency(cart.total_price) %></td> |
| | </tr> |
| | |
| | </table> |
In Slim, it would look like so:
| | h2 |
| | = t('.title') |
| | table |
| | = render(cart.line_items) |
| | |
| | tr.total_line |
| | td.colspan=2 |
| | Total |
| | td.total_cell |
| | = number_to_currency(cart.total_price) |
Slim treats each line as an opening HTML tag, and anything indented ...
Read now
Unlock full access