How to name Slices

I’ve run into an issue with naming my slices after I mistakenly created duplicates, as a result I have numbers appended to it.

Essentially I tried changing what started as PostBodyVideo to PostBodyMedia by renaming the slice in my slice-zone and re-saving, but that didn’t work. So upon deleting my PostBodyVideo slice called Media, and recreating it and being called Media to start with, I wound up with a slice in my schema called PostBodyMedia1

Functionally this has no real effect, but for sake of cleanliness, is it possible to change the name of a Slice?

It should be possible to rename it using the json schema editor. Can you post the relevant part of your schema ?
Consider the following schema extract

  "Seo" : {
    "seo" : {
      "type" : "Slices",
      "fieldset" : "Slice zone",
      "config" : {
        "labels" : { },
        "choices" : {
          "seo" : {
            "type" : "Slice",
            "fieldset" : "Seo",
            "description" : "seo information for this page",
            "icon" : "local_offer",
            "display" : "list",
            "non-repeat" : {
              "title" : {
                "type" : "Text",
                "config" : {
                  "label" : "Title",
                  "placeholder" : "description"
                }
              },
              "description" : {
                "type" : "Text",
                "config" : {
                  "label" : "Description"
                }
              },
              "indexable" : {
                "type" : "Boolean",
                "config" : {
                  "default_value" : false,
                  "label" : "indexable"
                }
              },
              "image1" : {
                "type" : "Image",
                "config" : {
                  "constraint" : { },
                  "thumbnails" : [ ],
                  "label" : "image"
                }
              }
            },
            "repeat" : { }
          }
        }
      }
    }
  },

This describes a Seo tab (toplevel key in the custom type object) in a custom type which has a slice section with a single slice named Seo (fieldset in the schema). the slice_type for the slice is seo (object key in the choices object)

It’s possible to change either the descriptive name of the slice (which is shown in prismic editor and is called fieldset in the schema) or the name of slice_type field by editing the choices key directly.
A word of warning about the latter, you will loose the corresponding information in all documents of this type by doing this. Note that the slice_type is used by slice-machine to determine the slice to be rendered, you should be very careful with renaming this as it will render with a different component.

What I usually do is I duplicate the key I want to change to it’s new key (preserving both types for a while), I edit all the documents of the corresponding type to duplicate the information then I remove the initial key.

yes it is every bit as painful as it sounds but in the absence of a write API or migration tool it’s not possible to automate it unless you can afford the Enterprise plan (which I can’t) in which case the import/export feature could be used to automate the change.

2 Likes

Thanks for the direction @jean.helou! Editing the json schema was part of the solution! :smiley: Turns out I also needed to re-publish a page which uses that slice.

All’s good now. Thanks again!

2 Likes