Reusable Slices within other slices

Is there any way with Prismic to create a slice and reuse it within other slices? A practical example would be the following:

Creating a button which when clicked opens up a modal with information. The slice built for this would have fields for:

  • Button Text
  • Modal Headline
  • Modal Text

Then I could use this slice within other slices, adding this modal button functionality to any other slices without having to repeat those fields for every slice where I want to use it. Another way to think about it is a component include.

Hello @ studio2, glad to see you join the community forum!

If I understood your use case correctly, you need to add specific fields to all of your Slices dynamically, but you don't want to add them to every Slice. You can solve this by adding a Boolean field or Select field that indicates if said Slice should be associated with a Modal Slice.

Another way of doing this is by adding variations to your Slices. But this is only available in projects that use Slice Machine.

Thanks for the suggestions! I'm not sure the Boolean would work, or I might be misunderstanding some Prismic functionality. Is there some kind of functionality where I can I show fields from another slice (within the editor experience) if a Boolean is toggled true?

For example, I have a 'Hero' slice and by default it shows 2 text fields and a Boolean toggle for 'Use modal' and if an editor toggles that on then it shows 3 additional fields from the 'Modal' slice. This would be exactly what I am looking for if it's possible!

No, the Boolean field would only work as an indicator for you to use in the front-end of your application.

In the case of Slice Machine, you can have the Hero Slice with a 'Use Modal' variations, which is exactly what you're looking for. But again, this is only available in Slice Machine.