FAQ / Using Mustache Loops (Advanced)

Loops are a good way to avoid writing a lot of code. They take the following form:

  1. A Mustache tag starting with a # and a glob expression.
  2. The content you want looped, using the metadata from each matched page.
  3. A Mustache tag with just a /.

For example, suppose you have three files blog/foo.md, blog/bar.md and blog/baz.md, then in an index.md file:

{{ # blog/* }}
- [{{ title }}]({{ url }})
{{ / }}

This will loop through all Markdown files in blog/ and create a list item with a link displaying the title, linked to the matched page’s URL, like this:

- [Foo](blog/foo)
- [Bar](blog/bar)
- [Baz](blog/baz)

Files beginning with _ will be ignored.

← Previous | Source | Next →