Document Manager adds nothing to the delivery side. Your website reads Document items with Contentful's standard APIs. The developer pages show how, with snippets from a working sample. This one covers the sample project and the content model.
The sample project#
The monorepo has a small Next.js site that reads a library through the Delivery API and renders library and folder pages with breadcrumbs and download links. It's in examples/document-manager-next. The snippets below are trimmed from it.
To run it:
- Install Document Manager, create a library and publish it with its folders and files.
- Copy
.env.exampleto.env.local. Add your space ID and a Content Delivery API token. SetDOCUMENT_ITEM_TYPEif your content type ID isn'tdocumentItem. - Run
npm install, thennpm run dev, and open http://localhost:3002.
Without those variables, every page shows setup steps. Its helpers in src/lib/tree.ts have no Contentful or Next.js imports, so you can copy them as they are.
Content model#
One content type, Document item, with the ID you chose at install (default documentItem).
| Field ID | Type | Used by | Notes |
|---|---|---|---|
title | Short text, required | all | 1 to 256 characters, localised |
kind | Short text, required | all | library, folder or file. Not localised. |
slug | Short text | all | Unique. Lower case letters, numbers and hyphens. Use it in website addresses. |
description | Rich text | all | Localised |
file | Media, one file | files | The file people download |
versionLabel | Short text | files | Optional, up to 50 characters, for example v3 |
items | References, many | libraries and folders | Links to Document items only. At most 1,000. The order is the order on your site. |
Admins can add custom fields in the content model. Read them for every kind.
| Kind | Meaning |
|---|---|
library | A top-level root. It isn't linked from another item. |
folder | Holds files and folders. |
file | One asset plus details. |
A file can be linked from several folders, so the data is a graph that is normally a tree. Example Delivery API response, trimmed:
{
"sys": { "id": "pres-pack", "contentType": { "sys": { "id": "documentItem" } } },
"fields": {
"title": "Presentation Pack",
"kind": "folder",
"slug": "presentation-pack",
"items": [{ "sys": { "type": "Link", "linkType": "Entry", "id": "slides" } }]
}
}Next: Fetching documents shows how to list libraries and fetch a whole tree.