[英]In PUG/JADE, how to avoid ambiguity between a variable name and a html tag?
I have a code like this in pug: 我在哈巴狗中有这样的代码:
var index=0
if user
each prog in user["progress"]
if prog.coursename === coursename
index=blabla
However, it seems that the variable "index" was treated as a tag instead of a variable and thus caused errors. 但是,似乎变量“ index”被视为标记而不是变量,从而导致错误。 So is there any way to avoid this ambiguity? 那么有什么方法可以避免这种歧义?
With pug any time you start a line with a character/string you will output a tag of that type. 任何时候使用pug开头的字符/字符串行,都将输出该类型的标签。 As you might have seen, .
如您所见, .
and #
have special meanings for class and id (respectively) and using those at the start of your line creates a plain old div
. 和#
分别对class和id具有特殊含义,并且在行的开头使用它们会创建一个普通的旧div
。
You can escape a line to only be code with a dash at the start of your line like this: 您可以将一行转义为仅在行首加上破折号的代码 ,如下所示:
- index = "blabla"
Note that the -
operator tells pug only to evaluate the code and not to output anything. 请注意, -
运算符告诉pug仅评估代码而不输出任何内容。 If you do want that code to output something, you need to use =
or !=
at the start of the line. 如果您确实希望该代码输出某些内容,则需要在该行的开头使用=
或!=
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.