Sindico Sindico - 1 year ago 161
Jade Question

printing elements of array in Pug

I am new to Jade/Pug template engine used in Express
I need to print out the name property of a list objects contained in an associative array passed as parameter to the pug template from an express route module.

I am trying in different ways like

each element in listOfElements
p #{}

where listOfElements is the name of the passed parameter

But I can't get the desired result


I am now trying to follow the doc which only provides a
example (not what I need).

According to the doc I am going like this

each element in listOfElements
li =

What I get on the rendered page is a list in which each bullet contains the " =" text

Answer Source

Going by the documentation on Pug website regarding iterations, you can get buffered code by placing an = right after the tag name. The docs for the same lie here. Therefore, in your second attempt, the following will work:

each element in listOfElements

However, as to the first attempt, I tried the following code, and it gave me the expected output (as shown after the snippet):

  each val in [{1:'a'}, {1:2}, {1:3}, {1:4}, {1:5}]
    li #{val[1]}


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download