嵌套呈现在haml中

时间:2015-03-09 10:06:03

标签: html ruby-on-rails ruby-on-rails-4 haml renderpartial

在" show.html.haml"中,我有两个这样的渲染:

= render 'project_header', :locals => {@set_tab => "current"}
= render 'project_toolbar'

我的" _project_header.html.haml"看起来像:

%article.project
  %header
    %h1.generated
      #some_code
    %h2
      #some_code

和我的" _project_toolbar.html.haml"看起来像:

%section.toolbar
   #some_code

这最终在html中看起来像:

<article class="project">
  #some_code
</article>
<section class="toolbar">
  #some_code
</section>

我想要的是

<article class="project">
   #some_code
   <section class="toolbar">
       #some_code
   </section>
</article>

我知道可以解决像渲染我的&#34; project_toolbar&#34;在&#34; project_header&#34;。但它们是两个逻辑上独立的实体,所以我不想这样做。 有什么建议吗?

1 个答案:

答案 0 :(得分:0)

它可能是haml,单向是

%article.project
  = render 'project_header', :locals => {@set_tab => "current"}
  = render 'project_toolbar'

或其他方式,在_project_header.html.haml中,呈现_project_toolbar.html.haml

%article.project
  %header
    %h1.generated
      #some_code
    %h2
      #some_code
  = render 'project_toolbar'