Syntax for if/else statement in Haml - unexpected keyword else?

I just switched to HAML and converting my erb to haml. I am experiencing an error (unexpected keyword else) when setting up the code as I think it should look:

= if signed_in?
  %li= link_to "Users", '#'
    %a.dropdown-toggle{ href: '#', data: { toggle: "dropdown" } } 
      %li= link_to "Profile", current_user
      %li= link_to "Settings", '#'
      %li= link_to "Log out", signout_path, method: "delete"
= else
  %li= link_to "Log in", signin_path

I have tried a number of things, but I can't seem to tackle the syntax error. I am sure it is a pretty basic thing for somebody who knows HAML. Any help is much appreciated!


You should replace = with - before if and else.

HAML is indentation based , and the parser can be tricky.You don't need to use "- end" in Haml. Use indentation instead.In Haml,a block begins whenever the indentation is increased after a Ruby evaluation command. It ends when the indentation decreases.Sample if else block as follows.

- if condition
  = something
- else
  = something_else


 ? Syntax error: Unexpected token else: specific code
 ? Codecademy "SyntaxError: Unexpected token else"
 ? SyntaxError: Unexpected token {
 ? JavaScript Syntax Error
 ? JavaScript Syntax Error
 ? JavaScript Syntax Error
 ? Javascript syntax error... How can I find out more information?
 ? Adding totals in javascript, syntax error
 ? JavaScript: Syntax Checking
 ? Where is the syntax error in this Javascript