We The Protesters
Eleventy
The possum is Eleventy’s mascot
Eleventy Documentation
Menu
Eleventy 5.81s
Gatsby 43.36s

Create Pages From Data

The Pagination feature is used for iterating over any data to create multiple output files.

Pagination can be used for traditional style pagination outputs like /result/page-0/, /result/page-1/. Pagination can also iterate over an object too and output any permalink value!

An Example Jump to heading

Let's look at an example where we dynamically build pages based on data from a json file. First let's consider this simple data file stored in _data/possums.json:

[
{
"name": "Fluffy",
"age": 2
},
{
"name": "Snugglepants",
"age": 5
},
{
"name": "Lord Featherbottom",
"age": 4
},
{
"name": "Pennywise",
"age": 9
}
]

In order to create one page per possum, we can use the following template. The file name isn’t important, but the file extension is (e.g. possum-pages.liquid or possum-pages.njk).

---
pagination:
data: possums
size: 1
alias: possum
permalink: "possums/{{ possum.name | slugify }}/"

---


{{ possum.name }} is {{ possum.age }} years old

This template will generate four files, one for each possum, where the filename is based on the possum's name passed through the slugify function. As possums are added and edited the resultant possum details page will be updated automatically.

INFO:
Note that page is a reserved word so you cannot use alias: page. Read about Eleventy’s reserved data names in Eleventy Supplied Data.

Other pages in Working with Templates: