Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haml render multiple partials in layout

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> 
like image 734
astropanic Avatar asked Sep 24 '10 21:09

astropanic


People also ask

How do I render a partial of a view?

To render a partial as part of a view, you use the render method within the view: This will render a file named _menu.html.erb at that point within the view being rendered.

How do I use partials in my application?

For content that is shared among all pages in your application, you can use partials directly from layouts. A partial can use its own layout file, just as a view can use a layout. For example, you might call a partial like this:

How do I render a partial response in HTML?

With a partial, you can move the code for rendering a particular piece of a response to its own file. To render a partial as part of a view, you use the render method within the view: This will render a file named _menu.html.erb at that point within the view being rendered.

Can a partial have its own layout file?

A partial can use its own layout file, just as a view can use a layout. For example, you might call a partial like this:


1 Answers

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"
like image 79
KARASZI István Avatar answered Sep 28 '22 02:09

KARASZI István