# Paged Plugin for DocPad
This plugin provides [DocPad](https://docpad.org) with Paging. Documents can declare a number of pages that should be rendered for the document, or a collection over which the document should be rendered repeatedly.
## Install
```
npm install --save docpad-plugin-paged
```
## Usage
### Setup
To use, simply add `isPaged: true` to the meta data for any document that you want to be rendered with paging. You can then use `pageSize` or `pagedCollection` to instruct the plugin how many pages to generate from this document.
In documents that have paging enabled we can use the `@document.page` object to retrieve information about the current and total pages. The `page` object is of the form:
```
{
number: 0, // current page number
count: 10, // total number of pages
size: 5, // expected number of documents per page
startIdx: 0, // document index for first document in this page
endIdx: 5 // document index for last document in this page
}
```
### Paging Collections
You can generate pages over a collection by using the `pagedCollection` meta property. Simply specify the name of a collection and the plugin will use this collections length to calculate how many pages to generate from this document. So if your `posts` collection contains 5 documents, and you have specified a `pageSize` of 3 then the paging plugin will render 2 pages, the first with documents 0-2 and the second with the remaining 2 documents.
### Example
For instance we could create the file `src/documents/index.html.eco` which contains something similar to the followìng:
```
---
title: 'Home'
layout: 'default'
tags: ['page']
isPaged: true
pageOrder: 0
pagedCollection: 'posts'
pageSize: 3
---
<% posts = @getCollection('posts') %>
<% for i in [@document.page.startIdx...@document.page.endIdx]: %>
<% document = posts.at(i).toJSON() %>
<%= document.title %>