html – Jade模板引擎:显示和隐藏某个块

我有一个玉模板

extends _base
block content
  include ./partials/_main-header
  .Template2RightBig
    .container
      .row
        block content2RightBig
          .col-md-3.Template2RightBig--left.column
            block left-column
          .col-md-9.Template2RightBig--right.column
            .Template2RightBig--right-header
              block right-column-header
            .Template2RightBig--right-annotation
              block right-column-annotation
            block right-column
  include ./partials/_footer

我想在页面中显示或隐藏右列注释块及其父容器(.Template2RightBig – right-annotation),这将扩展此页面.

我怎么能用翡翠力量做到这一点?

最佳答案 您可以通过新块将子页面中的变量传递到此模板,以便有条件地控制此模板中的任何内容.

_your-template.jade

extends _base
block content
  include ./partials/_main-header
  .Template2RightBig
    .container
      .row
        block content2RightBig
          block page-variables
          .col-md-3.Template2RightBig--left.column
            block left-column
          .col-md-9.Template2RightBig--right.column
            .Template2RightBig--right-header
              block right-column-header
            if rightAnnotationVisible === true
              .Template2RightBig--right-annotation
                block right-column-annotation
            block right-column
  include ./partials/_footer

_your-page.jade

extends _your-template

block page-variables
  - var rightAnnotationVisible = true
  //- annotation and parent wrapper will render

_your – 其他 – page.jade

extends _your-template

block page-variables
  - var rightAnnotationVisible = false
  //- annotation and parent wrapper won't render

只需确保新块的范围包含在父块中的正确位置.

点赞