What Is a Slice?
On this page, you'll learn what slices are and how you can use them to enrich the content modeling process.
Prismic slices are sections of your website. Prismic documents contain a dynamic "slice zone" that allows content creators to add, edit, and rearrange slices to compose dynamic layouts for any page design, such as blog posts, landing pages, and tutorials.
Repeatable zone replaced by repeatable group fields
In the past, every slice had one "non-repeatable zone" and one "repeatable zone." As of May 2024, users can now add multiple repeatable group fields to a slice.
A slice has three parts:
- A slice model, which is a JSON data model saved in Prismic.
- Slice content, which is the content for an instance of a slice.
- A slice template, which is a component in your project codebase.
Your slice model defines the shape of the slice content. Content creators can create an instance of a slice and fill it with slice content. Then your developer can create a slice template in the code, which will render the slice content.
These three parts — Model, Content, and Template — form a marriage between the CMS and your website, allowing editors to create and rearrange slices (website sections) freely without breaking the web app.
Your slices are managed inside slice zones.
The slice zone is where you can add and rearrange slices.
You can find it in four places:
In Slice Machine, slices become available in the page type's slice zone after creating them in the slices tab. Slices can be shared between page types.
In the Legacy Builder, the slice zone is where you create, edit, and manage all of the slice models.
Shared slices are not available in the Legacy Builder
Please note that, unlike Slice Machine, slices with the Legacy builder aren’t shared between types. You can create a copy of a slice and store it in the slice library, but new changes in the models for these slices will not be synchronized between types.
When editing a document, the slice zone gives authors the freedom to add and rearrange slices.
Note: Other names for the slice zone property
Most documents have one slice zone, stored in the body
property. However, you can change the name of this property in your page type. And, if you add additional slice zones to a page type, they will be named body1
, body2
, etc.
For example, for a page type with the API ID of page
you can access the slice zone in the data.body
array of objects which lists all the slices in the document. Here's a full example of this:
{
"id":"XxnD3REAACYAk_CJ",
"uid":"unique_value",
"type":"page",
"href":"https://your-repo-name.cdn.prismic.io/api/v1/documen8document.id%2C+%22XxnD3REAACYAk_CJ%22%29+%5D%5D",
"tags":["…"],
"first_publication_date":"2020-07-23T17:07:43+0000",
"last_publication_date":"2021-04-21T18:31:50+0000",
"slugs":["…"],
"linked_documents":["…"],
"lang":"en",
"alternate_languages":["…"],
"data":{
"body":[
{
"slice_type":"image_gallery",
"slice_label":null,
"items":["…"],
"primary":["…"]
}
]
}
}
In your project code, the SliceZone
is a component that renders slices with a conditional function (such as a switch
in JavaScript) inside of a loop (such as a forEach
in JavaScript).
The syntax of these loop cycles varies between technologies, and there are slice zone packages available for some technologies. Learn how to create a slice zone with your favorite technology.
Refer to the following document for how to create slices with Slice Machine:
The first step is to enable the slice zone in your newly created custom type. Click the switch button, and the Add a slice button will appear.
You'll see a configuration window to set the slice's name and description. Select an icon, and pick either List or Grid to define how items should appear in the repeatable section.
The slice zone is the object with all the slices in a page type. The following table displays the JSON structure for the slice zone.
body
object
Object to setup the slice zone
body.type
sting (required)
Value must be Slices
body.config
object
Configuration object for the slice zone
body.config.labels.[sliceID]
array
Key that matches a slice's API ID
body.config.labels.[sliceID].name
string
Defines the tag that will be displayed in the API response object for this slice
body.config.labels.[sliceID].display
string
Defines the display name for the tag in the document editor
body.config.choices
object
An object containing nested objects for each slice
The following table displays the JSON structure for each slice inside the slice zone. All slices are located inside body.config.choices
.
[sliceID]
string
Key that matches a slice's API ID
[sliceID].type
string (required)
The value must be Slice
[sliceID].fieldset
string
The display name for the slice in the document editor
[sliceID].description
string
The display description for the slice in the document editor
[sliceID].icon
string
The icon of the slice displayed in the document editor
[sliceID].non-repeat
object
The fields added to the slice
[sliceID].repeat
object
The fields added to the repeatable zone of a slice (deprecated)
Here is an API response example of a slice zone with three slices: author
, quote
and content
, each one with key text fields:
// API response example of a slice zone
{
// ...
"body":[
{
"slice_type":"quote",
"slice_label":null,
"primary":{
"quote_text":"consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
}
},
{
"slice_type":"content",
"slice_label":null,
"primary":{
"content_text":"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo."
}
}
]
}
Can't find what you're looking for?
Need technical Support? Spot an error in the documentation? Get in touch with us on our Community Forum.