[英]Can't change jade variable
I'm gonna keep this short. 我要保持简短。 I have this code: 我有以下代码:
- var title = 'title'
block content
h1= title
p Welcome to #{title}
Why does this not work? 为什么这不起作用? I have tried it without the variable and it works perfectly the, so the problem is about the variable. 我试过了没有变量,它可以完美地工作,所以问题出在变量上。
The problem was that since index.jade extended layout, when I defined the variable inside index.jade and then referenced it inside the block content, the references to it came before the definition. 问题在于,由于index.jade扩展了布局,因此当我在index.jade内定义变量,然后在块内容内对其进行引用时,对该变量的引用要先于定义。
The fix is simple: either define the variable in block content too: 修复很简单:也可以在块内容中定义变量:
block content
- var title = 'title'
h1= title
p Welcome to #{title}
Or if you want it to be able to the layout.jade too, just define it at the top of layout.jade. 或者,如果您也希望它能够对layout.jade进行操作,只需在layout.jade的顶部进行定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.