E
E
Ernest Faizullin2015-11-01 00:18:32
JavaScript
Ernest Faizullin, 2015-11-01 00:18:32

What is the correct way to use each in jade?

Here is an example that throws an error because of the each loop:

doctype html
html(lang="en")
head
  meta(charset="UTF-8")
  title= title
  link(rel="stylesheet", href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css")
body
  .container
    h1= title
    
    ul
      each link in links
        li= link

Mistake:
SyntaxError: Unexpected token (1:18)
at Parser.pp.raise (E:\projects\angular\node_modules\jade\node_modules\with\node_modules\acorn\dist\acorn.js:1745:13)
at Parser.pp. unexpected (E:\projects\angular\node_modules\jade\node_modules\with\node_modules\acorn\dist\acorn.js:2264:8)
at Parser.pp.parseBindingAtom (E:\projects\angular\node_modules\jade\node_modules \with\node_modules\acorn\dist\acorn.js:1876:12)
at Parser.pp.parseMaybeDefault (E:\projects\angular\node_modules\jade\node_modules\with\node_modules\acorn\dist\acorn.js:1920 :23)
at Parser.pp.parseBindingList (E:\projects\angular\node_modules\jade\node_modules\with\node_modules\acorn\dist\acorn.js:1896:23)
at Parser.pp.parseFunctionParams (E:\projects\angular\node_modules\jade\node_modules\with\node_modules\acorn\dist\acorn.js:2776:22)
at Parser.pp.parseFunction (E:\projects\angular\ node_modules\jade\node_modules\with\node_modules\acorn\dist\acorn.js:2769:8)
at Parser.pp.parseExprAtom (E:\projects\angular\node_modules\jade\node_modules\with\node_modules\acorn\dist\ acorn.js:1129:19)
at Parser.pp.parseExprSubscripts (E:\projects\angular\node_modules\jade\node_modules\with\node_modules\acorn\dist\acorn.js:1023:19)
at Parser.pp.parseMaybeUnary (E:\projects\angular\node_modules\jade\node_modules\with\node_modules\acorn\dist\acorn.js:1004:19)

The indentation is correct. Everything seems to be in the documentation. Why might this be so?
UPD: In links is a regular array with strings. Even if you make
each link in ['link1', 'link2', 'link3'], the error remains

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2015-11-01
@erniesto77

In general, your code works fine if you copy-paste it here: jade-lang.com (well, except that it swears at undefined links). So I don't know what to advise. Make sure jade is up to date, clear the npm cache, delete the node_modules folder in the project, and reinstall the dependencies again.

The indentation is correct.
By the way, not really :) head and body must be retreated, otherwise it turns out <html></html>at the beginning.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question