gpt4 book ai didi

html - Jade 模板引擎 : show and hide a certain block

转载 作者:搜寻专家 更新时间:2023-10-31 08:44:04 25 4
gpt4 key购买 nike

我有一个 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

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

我如何使用 Jade 能量做到这一点?

最佳答案

您可以通过新 block 将变量从子页面传递到此模板,以便有条件地控制此模板中的任何内容。

_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-other-page.jade

extends _your-template

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

只需确保新 block 的范围限定为包含在父 block 中的正确位置即可。

关于html - Jade 模板引擎 : show and hide a certain block,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29891610/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com