Rendering the Number field

Prismic no longer recommends the gatsby-source-prismic-graphql plugin

With recent changes to Gatsby, Prismic no longer recommends the gatsby-source-prismic-graphql plugin that this documentation uses. Read more about the future of Prismic and Gatsby. We highly recommend using the gatsby-source-prismic instead. The documentation for this plugin can be found in the plugin's github README.

We will leave this documentation here for now, but will change it in the future when we determine the best approach for Prismic & Gatsby.

The Number field allows content writers to enter or select a number. You can set max and min values for the number.

Access the Number field value

Here's an example that shows how to access the Number field value. In this case, the Number field has the API ID price. This assumes that you have saved the document object in a variable named document as shown in the Retrieve the document object page.

Copy
const price = document.price

A full example

Now let's take a look at a full page component example. Here you can see how the Number field is included in the query, retrieved, and templated on the page. Again in this example the API ID of the Number field is price.

Copy
import React from 'react'
import { graphql } from 'gatsby'

const Page = ({ data }) => {
  const prismicContent = data.prismic.allPages.edges[0]
  if (!prismicContent) return null
  const document = doc.node

  return (
    <h3 className="price">${document.price}</h3>
  )
}

export const query = graphql`
query {
  prismic {
    allPages(uid: "number-page") {
      edges {
        node {
          price
        }
      }
    }
  }
}
`

export default Page