Inherting custom types

I started working with Prismic a few days ago. The setup has been quite seamless so far, and I've had little to no issue integrating my own custom types and setting up the API with a NestJS (express) backend. I'm working on providing a few custom type fields for SEO purposes: things like description, title, image, etc. These fields are rendered to meta tags by the server. They are declared on my page custom type on a tab named Meta.

I want to use those same fields on a different custom type. Is there a way to inherit content types or their fields? I simply want to avoid having to add the fields on every custom type I create, so an option for a custom type to inherit fields from another would be helpful.

For example, could a new custom type - say landing - inherit the tab that declares the SEO fields from the page custom type? This would make it to where I don't have to maintain several fields that are essentially global to the application.

Any help or insights would be great since I'm new to Prismic.

Hello Marshal, welcome to the Community!

I can recommend you to create a Custom Tagging system.

That way, you can create a Custom type with the name 'Meta' with the fields that you mentioned earlier, like this:

{
  "Main": {},
  "meta": {
    "title": {
      "type": "StructuredText",
      "config": {
        "single": "heading1, heading2, heading3, heading4, heading5, heading6",
        "label": "title",
        "placeholder": "title"
      }
    },
    "description": {
      "type": "StructuredText",
      "config": {
        "multi": "paragraph, preformatted, heading1, heading2, heading3, heading4, heading5, heading6, strong, em, hyperlink, image, embed, list-item, o-list-item, rtl",
        "label": "description",
        "placeholder": "description"
      }
    },
    "image": {
      "type": "Image",
      "config": {
        "constraint": {},
        "thumbnails": [],
        "label": "image"
      }
    }
  }
}

Then, add a Content relationship field in any other Custom types where you want to use this metadata.

This issue has been closed due to inactivity. Flag to reopen.

@Pau Hi! I was looking the same thing as the post author, and i was also investigating your answer. I believe, but maybe i'm wrong, that there's no possibile way to obtain what the user was asking. What i would like to do is the following:

  • I create a Custom Type, that i would name GlobalMeta, which contain basic and global info, like name, title and image.
  • Then i create another Custom type, which let's say is a BlogPost, and then inside i would like to add the relationship to the GlobalMeta Custom Type, in a way that when i then create a new BlogPost document, i can see the three fields declared in the GlobalMeta Custom Type.

I've tried but i can't make it work that way, am i wrong?

Thanks a lot!

Hey @dev.wildtrek, thanks for reaching out!

The content relationship field allows you to do just that, create a 'relationship' between the two documents.

The information from the GlobalMeta will become available inside the BlogPost Custom Type, but it won't be visible in the UI of the repository. To access it, you need to create a query using graphQuery or fetchLinks to fetch the linked document data

@Pau Thanks for the answer!
So basically it isn't possible yet to create reusable Custom Types to extend and to use in the repository right? I mean, i can't have all reusable UI fields in just one place and reuse them?

That is the main quality of repeatable Custom Types, that they are reusable. Maybe I need to know more about your use case to understand. If you need to repeat fields within the same Custom Type then perhaps Slices are what you need.