I want to use a pug template file to render html. Here is the pug file temp1.pug:
h1 hello!
p here is my friends:
ul
each val,index in !{friends}
li='friend'+(index+1)+ ' ' + val
I want to render the pug file by using array in parameter friends:
const templateRender = pug.compileFile('./temp1.pug');
console.log(templateRender({friends:['aaa','bbb']}));
It is supposed to have the output like:
<h1>hello!</h1>
<p>here is my friends:
<ul>
<li>friend 1: aaa</li>
<li>friend 2: bbb</li>
</ul>
</p>
but the actual output is:
<h1>hello!</h1>
<p>here is my friends:
<ul></ul>
</p>
It seemed that pug complier completely ignore my array input. Is there any idea to use array parameters to render this page?
Please try this:
each val,index in friends