Haml render multiple partials in layout

astropanic picture astropanic · Sep 24, 2010 · Viewed 11.6k times · Source

How can I make the code indent correctly?

app/views/layouts/shared.html.haml:

= render :partial => "shared/head"
= yield
= render :partial => "shared/footer"

app/views/shared/_head.html.haml:

!!!XML
!!!1.1
%html{"xml:lang" => "pl", :xmlns => "http://www.w3.org/1999/xhtml"}
  %head
    %title
      some title
  %body
    .container

app/views/shared/index.html.haml:

%p
  Hello World!

app/views/shared/_footer.html.haml:

.footer
  Some copyright text

Rendered HTML output:

<!DOCTYPE html> 
<html xml:lang='pl' xmlns='http://www.w3.org/1999/xhtml'> 
  <head> 
    <title> 
      some title
    </title> 
  </head> 
  <body> 
    <div class='container'></div> 
  </body> 
</html> 
<p> 
  Hello World!
</p> 
<div id='footer'> 
 Some copyright text
</div> 

Answer

KARASZI Istv&#225;n picture KARASZI István · Sep 24, 2010

You should use app/views/layout for that and yield the actual content:

Example

Update

app/views/layout/shared.html.haml:

!!! 1.1
%html
  = render "shared/head"
  %body
    .container
      = yield
  = render "shared/foot"