views:

152

answers:

2

I'm pretty new to rails and haml.. and I can't get this to work right.

I have this partial (_head.html.haml):

!!!
%html
  %head
    %meta{'http-equiv' => 'Content-Type', :content => "text/html; charset=iso-8859-1"}
    = stylesheet_link_tag 'main'
  %body

And then in my application.html.haml:

= render :partial => 'shared/head'
#wrapperDIV 
  = yield :layout

But the output is not exactly what I intend:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html>
  <head>
    <meta content='text/html; charset=iso-8859-1' http-equiv='Content-Type' />
    <link href="/stylesheets/main.css?1266030236" media="screen" rel="stylesheet" type="text/css" />
  </head>
  <body></body>
</html>
<div id='wrapperDIV'></div>

Obviously <html> and <body> should wrap #wrapperDIV, but it seems like the partials are not getting put in the right hierarchy.

Any ideas? Thx

+1  A: 

The html and body needs to be in application.html.haml

!!!
%html
  = render :partial => 'shared/head'
  %body
    #wrapperDIV 
      = yield :layout
Jonathan Julian
I tried that, but then `html` still doesn't wrap `body`. There has to be a way for this to work though..
Infinity
Everything that you want to wrap the content of the page needs to be in `application.html.haml`, including both `html` and `body`.
nex3
That's right, my example should also have !!! and %html at the top.
Jonathan Julian
+1  A: 

Partials are implicitly closed at the end. They're supposed to be complete sub-objects.

Here's what you want:

!!!
%html
  %head
    %meta{'http-equiv' => 'Content-Type', :content => "text/html; charset=iso-8859-1"}
    = stylesheet_link_tag 'main'
  %body
    #wrapperDIV 
      = yield :layout

If you wanted to put your meta and stylesheet calls in a partial, you could do that, but all the tags you have open at the end of a haml document will be closed.

wesgarrison