Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loop in Jade (currently known as "Pug") template engine

I want to use a simple loop like for(int i=0; i<10; i++){}.

How do I use it in the Jade engine? I'm working with Node.js and use the expressjs framework.

like image 462
Huy Tran Avatar asked Jan 04 '12 14:01

Huy Tran


People also ask

What is Jade templating?

Jade is a template engine for node. js and the default rendering engine for the Express web framework. It is a new, simplified language that compiles into HTML and is extremely useful for web developers. Jade is designed primarily for server-side templating in node.

How do you use Pug variables?

The names of the variables in your Pug file become siteColors and siteNames . To set the entirety of an HTML element equal to a variable, use the equals operator = to do so. If your variable needs to be embedded inline, use bracket syntax #{} to do so.


2 Answers

for example:

- for (var i = 0; i < 10; ++i) {   li= array[i] - } 

you may see https://github.com/visionmedia/jade for detailed document.

like image 84
qiao Avatar answered Oct 04 '22 04:10

qiao


Using node I have a collection of stuff @stuff and access it like this:

- each stuff in stuffs   p     = stuff.sentence 
like image 21
thenengah Avatar answered Oct 04 '22 04:10

thenengah