user2945241
user2945241

Reputation: 360

HAML close tags only in parent file

lately in our project we are trying to migrate most of our view files to HAML from ERB. Today i stubbled upon a problem, which i can't figure out.

I have file structure like this

  -- _header.html.haml
  -- index.html.haml
  -- show.html.haml

In our header file we open some of the tags for example:

_header.html.haml

%section.page
 .wrapper

but in index and show files we render this header partial like this

index.html.haml

= render "layouts/structure/faq_header"

%section.noborder{ id: "fp-1" }
  %h2{id: "c1"}= @question_group.title

When HAML is compiled to html all of the tags are closed in _header.html.haml file at the end, but i need them to close only in the parent file, is it even possible, if not are there any workaround so the end result would look like this:

<section class="page">
  <div class="wrapper">
    <section class="noborder" id="fp-1">
      <h2 id="c1">
        <%= @question_group.title %>
      </h2>
    </section>
  </div>
</section>

not like this:

   <section class="page">
      <div class="wrapper">
      </div>
   </section>
   <section class="noborder" id="fp-1">
     <h2 id="c1">
       <%= @question_group.title %>
     </h2>
   </section>

Upvotes: 0

Views: 342

Answers (1)

BroiSatse
BroiSatse

Reputation: 44715

You need to use your header file as a layout:

# _header.html.haml
%section.page
 .wrapper
   = yield


#index.html.haml

= render layout: "_header" do
  %section.noborder{ id: "fp-1" }
    %h2{id: "c1"}= @question_group.title

Upvotes: 2

Related Questions