0

I'd like to use full html syntax with Slim. I don't want the cryptography they offer. But I think it's impossible. Here's my html code and Slim throws an error.

The target:

I want not to output an additional class of div element if some condition is met:

<div class="foo bar"></div>   # <-- standard
<div class="foo"></div>   # <-- no "bar" class if some condition is met

And here is my Slim code:

<body> # <-- 11th line
    - (1..5).each do |i|   # <-- The dash means a line of Ruby code...
        <div class="foo    # <-- ...after it an indentation of lines follows
           - if(i != 2)    #  <-- if "i" is not 2
                = bar         # <-- output "bar" as additional class for the div
            = " data-co="#{i}">  # <-- indentation back, I want an output of the rest 
      </div>
</body> # <-- 17th line

</html> # <-- 19th line, the last element

Logically everything is all right. All indentations and = and - are obeyed. But I get error:

!! Unexpected error while processing request: tmpl.slim:16: syntax error, unexpected keyword_end, expecting ')
'
; end; _buf << ("</div>");
     ^
tmpl.slim:17: syntax error, unexpected keyword_end, expecting ')'
; end; _buf << ("</body>"\
     ^
tmpl.slim:22: syntax error, unexpected keyword_end, expecting ')'
end;end;end;end

I have two questions:

1) Is it possible to fully use html syntax in Slim?

2) How may I solve my issue?

Green
  • 28,742
  • 61
  • 158
  • 247

1 Answers1

1

I think you are thinking this the wrong way. If your end goal is to produce two types of opening tags based on one condition, then a simple if else statement will work, which is sort-of what you did. But, because you were writing in multiple lines in an HTML opening tag, SLIM freaked out. Try this out and let me know what happens.

<body>
  - (1..5).each do |i|   
     - if i.eql? 2
       <div class="foo"> 
     - else
       <div class="foo bar" data-co="#{i}">   
     </div>
</body>
thank_you
  • 11,001
  • 19
  • 101
  • 185
  • Yes, this works! :) I see now the difference. I wanted to add only class name without duplicating of `
    ...
    ` line. Now I see how to solve it. Thank you.
    – Green Apr 07 '13 at 21:51