Custom Slice Template

Hello, beautiful people

I double checked documentation and didn't found this awesome feature. So I consider sharing it.

If you create slice-template folder inside your project. SM will take template from this folder. In our case we are using typescript so this is big.

example we are using same default slice just with types.

Folder structure:

Screenshot 2021-02-22 at 10.13.59

Slice template:

Screenshot 2021-02-22 at 10.14.20

I hope this will be useful for someone and added to documentation in future.

Good luck! :heart::cherry_blossom:

2 Likes

Thanks Arnas,

I wasn't aware of this capability :slight_smile:

I'll update the documentation to include this.

Thanks again.

Hi!
We're using this for typescript as well and its working great! It acted exactly as expected but I found myself scratching my head when my new slice didn't appear in storybook. This is because the hardcoded slice name "name": "MySlice" in my model and mock did not update when copied over when the slice was created.

I looked for docs hoping to see if there is some secret token I can use to mark the name for replacing, e.g "name": "{{slicename}}", or whatever. You get the idea.

Not asking for a feature per se, but if it's not currently possible, the ability would be tight. If I end up finding a way I'll post here. If anyone else knows whats up, please share :pray:

Hi William,

This isn't something that's possible with the current version of the Prismic CLI, but we have been working on an improved version of the CLI which will include this functionality in the templates.

Once this new version is released we'll let you know here. :slightly_smiling_face:

Thanks.