Awesomeness
Awesomeness

Reputation: 2631

HAML - why does my haml's text all show up on top line, despite being rendered on diff parts of the code

I have this HAML page:

-content_for :primary_content do

  Hmmm
  %strong{:class => "code", :id => "message"} Hello Alex!

  .container-fluid
    .row-fluid
      .span1 Hello 1
      .span4 Hello 4
      .span4 Hello 4 again
      .span3 Hello 3

  %strong{:class => "code"} End of page!

  .container-fluid
    .row-fluid
      .span9 My Disclosures o ye!
      .span3 This will be the side area

      // Ok....what is in home?
      // The two divs....

  -content_for :primary_content do
    -if signed_in?
      // =render "sidebar/common/primary_navigation"
      // If signed in, show the options for
      // 1) Logout | My Profile
      // 2) Create disclosure | show disclosures
      Signed in
    -else
      // =render "devise/sessions/form"
      NOT Signed in

For some reason it renders Not signed in Hmmm Hello Alex! on the top line and then everything else below it.

I am confused since "Not Signed In" is on the bottom of the page, and the "hmm Hello Alex" is on top. But for some reason it renders together on the screen. Any idea why?

Thanks!

Upvotes: 1

Views: 164

Answers (1)

Eric C
Eric C

Reputation: 2205

First I'd like to point out that you seem to have a nested content_for, this may be an issue.

Secondly, I recommend separating the two content_for blocks and creating another one specifically for the login area. Something like

- content_for :login do
  -if signed_in?
    // =render "sidebar/common/primary_navigation"
    // If signed in, show the options for
    // 1) Logout | My Profile
    // 2) Create disclosure | show disclosures
    Signed in
  -else
    // =render "devise/sessions/form"
    NOT Signed in

Then put

yield :login

somewhere after

yield :primary_content

Separating concerns and making it so you don't have any content stepping on the others toes.

Upvotes: 2

Related Questions