【问题标题】:HAML close tags only in parent file仅在父文件中的 HAML 关闭标签
【发布时间】:2014-09-25 19:24:59
【问题描述】:

最近在我们的项目中,我们尝试将大部分视图文件从 ERB 迁移到 HAML。 今天偶然发现一个问题,我想不通。

我有这样的文件结构

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

在我们的头文件中,我们打开一些标签,例如:

_header.html.haml

%section.page
 .wrapper

但是在 index 和 show 文件中,我们将这个 header 部分渲染成这样

index.html.haml

= render "layouts/structure/faq_header"

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

当 HAML 被编译为 html 时,所有标签最后都在 _header.html.haml 文件中关闭,但我需要它们仅在父文件中关闭,是否有可能,如果没有,是否有任何解决方法所以最终结果如下所示:

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

不是这样的:

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

【问题讨论】:

    标签: ruby-on-rails ruby haml


    【解决方案1】:

    你需要使用你的头文件作为布局:

    # _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
    

    【讨论】:

      猜你喜欢
      • 2012-03-04
      • 1970-01-01
      • 1970-01-01
      • 2017-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-05
      相关资源
      最近更新 更多