The Document object
This page describes the document object returned from the Prismic API.
Before Reading
This page assumes that you have already retrieved a document from your Prismic repository and stored it in a variable named document.
Let's start by taking a look at the document object returned when querying the API. Here is a simple example of a document that contains a couple of fields.
Copy
{
"id": "WKxlPCUEEIZ10AHU",
"uid": "example-page",
"type": "page",
"href": "https://your-repo-name.prismic.io/api/documents/search...",
"tags": [
"Tag 1",
"Tag 2"
],
"first_publication_date": "2017-01-13T11:45:21.000Z",
"last_publication_date": "2017-02-21T16:05:19.000Z",
"slugs": [
"example-page"
],
"linked_documents": [],
"lang": "en-us",
"alternate_languages": [
{
"id": "WZcAEyoAACcA0LHi",
"uid": "example-page-french",
"type": "page",
"lang": "fr-fr"
}
],
"data": {
"title": [
{
"type": "heading1",
"text": "Example Page",
"spans": []
}
],
"date": "2017-01-13"
}
}
Copy
document.id
Copy
document.uid
Copy
document.type
Copy
document.href
Copy
document.tags
// returns an array
Copy
document.first_publication_date
Copy
document.last_publication_date
Copy
document.lang
Copy
document.alternate_languages
// returns an array
You can read more about this in the Multi-Language info page.
To retrieve the content fields from the document you must specify the API ID of the field. Here is an example that retrieves a Key Text field's content from the document. Here the Key Text field has the API ID of name.
Copy
document.data.name
Refer to the specific templating documentation for each field to learn how to add content fields to your pages.