views:

77

answers:

1

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'&gt; 
  <head> 
    <title> 
      some title
    </title> 
  </head> 
  <body> 
    <div class='container'></div> 
  </body> 
</html> 
<p> 
  Hello World!
</p> 
<div id='footer'> 
 Some copyright text
</div> 

How to make the code indent correctly ?

+1  A: 

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

example

update

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

!!!XML
!!!1.1
%html{"xml:lang" => "pl", :xmlns => "http://www.w3.org/1999/xhtml"}
  = render :partial => "shared/head"
  %body
    .container
      = yield
  = render :partial => "shared/foot"
KARASZI István
When I want to use the same header partial on multiple layouts I must repeat it on all my layouts...not very DRY and not the "Ruby way"
astropanic
layouts are exactly for your problem, if you have more layouts with the same subcontent render those part from the common places
KARASZI István
I have placed an example above, a simple layout with included head and footer, but as you can see it doesn't work
astropanic
As you can see on Your example, when You have more layouts, for each of them You need to copy the first 6 lines... ugly aproach
astropanic
6 lines is not a big price for using haml
KARASZI István