0

I'm new to slim and there are little things that I don't understand and I don't find answers in the documentation.

  1. linebreak - How can I add this at the end of a line? For example:

    <%= name %><br/>

    <%= address %><br/>

  2. How can I combine pure html and ruby on the same line? For example:

    <p>New building <% if building.ownver %> for <%= owner %><% end %></p>

I know, I must have missed something but there is no real tutorial out there.

BTW, There is no emulator to convert erb to slim?

Thanks.

Andrei Botalov
  • 20,686
  • 11
  • 89
  • 123
ndemoreau
  • 3,849
  • 4
  • 43
  • 55
  • In erb, I tend to use `

    New building <%= "for #{owner}" if building.owner %>

    ` rather than `

    New building <% if building.owner %> for <%= owner %><% end %>

    ` for these scenarios.
    – James Chevalier Jul 17 '13 at 16:51
  • It's indeed cleaner but less appropriate to illustrate my question! ;-) – ndemoreau Jul 18 '13 at 06:10

2 Answers2

3

You can use this converter html to slim here's a link!

Sergey Chechaev
  • 562
  • 7
  • 22
1

The documentation covers this here: https://github.com/slim-template/slim#inline-html--html-style

The example it gives is:

<html>
  head
    title Example
  <body>
    - if articles.empty?
    - else
      table
        - articles.each do |a|
          <tr><td>#{a.name}</td><td>#{a.description}</td></tr>
  </body>
</html>

I don't know if there's an equivalent to the erb <%= "for #{owner}" if building.ownver %> in slim, so I would just use the above information for your second question, as well, by changing the code to:

- if building.ownver
  <p>New building</p>
- else
  <p>New building for #{owner}</p>
James Chevalier
  • 10,604
  • 5
  • 48
  • 74
  • If I understand right, the solution to my first question would be: #{name}
    ? Seems to work but strange. What would then be the answer to the second question? Thx!
    – ndemoreau Jul 18 '13 at 06:11