Skip to content

Commit

Permalink
docs for previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Aug 25, 2011
1 parent e16bc02 commit 617acb7
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -549,15 +549,18 @@ you may use `!=`:

p!= aVarContainingMoreHTML

The one exception made in terms of allowing "vanilla" JavaScript, is
the `- each` token. This takes the form of:
## Iteration

- each VAL[, KEY] in OBJ
Along with vanilla JavaScript Jade also supports a subset of
constructs that allow you to create more designer-friendly templates,
one of these constructs is `each`, taking the form:

each VAL[, KEY] in OBJ

An example iterating over an array:

- var items = ["one", "two", "three"]
- each item in items
each item in items
li= item

outputs:
Expand All @@ -569,7 +572,7 @@ outputs:
iterating an array with index:

- var items = ["one", "two", "three"]
- each item, i in items
each item, i in items
li #{item}: #{i}

outputs:
Expand All @@ -581,28 +584,16 @@ outputs:
iterating an object's keys and values:

- var obj = { foo: 'bar' }
- each val, key in obj
each val, key in obj
li #{key}: #{val}

would output `<li>foo: bar</li>`

You can also nest these!

- each user in users
- each role in user.roles
li= role

When a property is undefined, Jade will output an empty string. For example:
Internally Jade converts these statements to regular
JavaScript loops such as `users.forEach(function(user){`,
so lexical scope and nesting applies as it would with regular
JavaScript:

textarea= user.signature

when undefined would normally output "undefined" in your html, however recent
versions of Jade will simply render:

<textarea></textarea>

Jade also now supports `each` without the code prefix (`-`):

each user in users
each role in user.roles
li= role
Expand Down

0 comments on commit 617acb7

Please sign in to comment.