On this page you'll learn how to reuse a Slice in different Custom Types.
Slices allow you to add recurring content components that appear across different pages of a website. It's useful to make them reusable so that you can insert them into any Custom Type.
Prismic has two ways of storing Slices:
- Using the Slice Library. All the Slices you save inside the Custom Type builder will be saved in the Slice Library of your repository.
- Using Slice Machine's Shared Slices. All the Slices you create using the Slice Builder in Slice Machine will be saved in the Shared Slices of your repository.
Although these two options have a common goal (making Slices reusable), they are very different processes. The biggest difference is that Shared Slices work with projects that use Slice Machine.
The Slice Library
The Slice Library is available in all repositories. It's the place where you can save a copy of all the Slices created using the Build Mode of the Custom Type builder.
Add Slices to the library
You can add Slices to the Slice Library from the Custom Type editor.
- Open a Custom Type and find the Slice you want to reuse.
- Click on the Save button at the bottom of the Slice to add it to the Slice library.
After that, whenever you open any other Custom Type and click on Add a slice and then Use an existing Slice, you'll see your saved Slices in My Slice library.
Additionally, Prismic gives you a set of predefined Slices below the Slice Library that you can add to any Custom Type.
Update the new Slices between Custom Types
Slices are saved to the library as copies, and changes to the original are not reflected in the copy. It's important to remember that if you make changes to your Slice, you will need to re-save it to your Library and re-add it where you need to.
Shared Slices are only available in repositories that use Slice Machine. It's the place where all Slices created using Slice Machine's Slice Builder are saved. By default, any Slices created with Slice Machine will be available everywhere across your repository.
Add Slices to your shared Slices
The Slice Builder is not accessible from the repository’s UI. You need to open your project's code and run the command that launches the Slice Builder.
The process of setting up a development environment, installing dependencies, and running the necessary commands is beyond the scope of this article.
When you create a Slice with Slice Machine and push it to your repository, it'll be accessible in your Shared Slices. You can then add the Slice to any Custom Type in the Custom Type editor.
Was this article helpful?
Can't find what you're looking for? Get in touch with us on our Community Forum.