我希望通过在继承基本布局的模板中声明一个变量,为body标签设置一个类。
但是当我尝试时,在布局中body_class
变量为undefined
。
似乎布局在扩展模板之前执行,或者它们在不同的作用域中执行。
还有其他方法吗?使用mixin可以解决这个问题吗?
_layout.jade:
doctype html
html(lang="en-au")
head
meta(charset="utf-8")
block css
body(class=(body_class || "it-did-not-work"))
block header
block content
block footer
home.jade:
var body_class = 'i-am-the-home-page'
extends _layout
block header
h1 home