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. 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. 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
.
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. If you do want that code to output something, you need to use =
or !=
at the start of the line.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.