Enhancement: Allow content type to have a parent content type. #334

Closed
opened 2026-10-05 02:41:13 +02:00 by adam · 2 comments
Owner

Hugo default content type (which frontmatter almost complete description can be found at the end of this text) can be extended with custom content type. Frontmattter allow for custom content type definition, but does not allow these content type to inherit fields from others content types. In Hugo case, adding a complex content type based on hugo default features add a lot of content to frontmatter.json and make it unreadable.

A easy solution should be to allow for content types to have a parent content type of which they inherit the fields.

A more complex but adaptable solution should be to allow for content types to have multiple parents of which they inherit the fields.

Here is the frontmatter.json extract for an mostly complete Hugo default content type to give you an idea of the length of a complete Hugo content type:

  "frontMatter.taxonomy.contentTypes": [
    {
      "name": "default",
      "previewPath": "",
      "pageBundle": false,
      "fields": [
        {
          "title": "Title",
          "name": "title",
          "type": "string",
          "single": true
        },
        {
          "title": "Link title",
          "name": "linkTitle",
          "type": "string",
          "single": true
        },
        {
          "title": "Slug",
          "name": "slug",
          "type": "slug",
          "editable": true
        },
        {
          "title": "URL",
          "name": "url",
          "type": "string",
          "single": true
        },
        {
          "title": "Output formats",
          "name": "outputs",
          "type": "choice",
          "multiple": true,
          "choices": [
            "",
            "HTML",
            "AMP",
            "CSS",
            "CSV",
            "Calendar",
            "JSON",
            "MARKDOWN",
            "ROBOTS",
            "RSS",
            "Sitemap",
            "WebAppManifest"
          ],
          "default": "",
          "hidden": true
        },
        {
          "title": "Description",
          "name": "description",
          "type": "string",
          "single": false
        },
        {
          "title": "Summary",
          "name": "summary",
          "type": "string",
          "single": false
        },
        {
          "title": "Navigation weight",
          "name": "weight",
          "type": "number"
        },
        {
          "title": "Is in draft",
          "name": "draft",
          "type": "draft",
          "default": true
        },
        {
          "title": "Content date",
          "name": "date",
          "type": "datetime",
          "default": "{{now}}",
          "isPublishDate": false
        },
        {
          "title": "Publishing date",
          "name": "publishDate",
          "type": "datetime",
          "default": "{{now}}",
          "isPublishDate": true
        },
        {
          "title": "Expiration date",
          "name": "expiryDate",
          "type": "datetime",
          "default": null,
          "isPublishDate": false
        },
        {
          "title": "Last modified date",
          "name": "lastmod",
          "type": "datetime",
          "default": "{{now}}",
          "isModifiedDate": true
        },
        {
          "title": "Is headless bundle",
          "name": "headless",
          "type": "boolean",
          "default": false,
          "hidden": true
        },
        {
          "title": "Image",
          "name": "images",
          "type": "image",
          "multiple": true,
          "isPreviewImage": true
        },
        {
          "title": "Is CJK language",
          "name": "isCJKLanguage",
          "type": "boolean",
          "default": false,
          "hidden": true
        },
        {
          "title": "Layout",
          "name": "layout",
          "type": "string",
          "single": true,
          "hidden": true
        },
        {
          "title": "Aliases",
          "name": "aliases",
          "type": "list",
          "hidden": true
        },
        {
          "title": "Categories",
          "name": "categories",
          "type": "categories"
        },
        {
          "title": "Tags",
          "name": "tags",
          "type": "tags"
        },
        {
          "title": "Audio",
          "name": "audio",
          "type": "list",
          "hidden": true
        },
        {
          "title": "Videos",
          "name": "videos",
          "type": "list",
          "hidden": true
        },
        {
          "title": "Content type",
          "name": "type",
          "type": "string",
          "single": true
        }
      ]
    }
  ]
Hugo default content type (which frontmatter almost complete description can be found at the end of this text) can be extended with custom content type. Frontmattter allow for custom content type definition, but does not allow these content type to inherit fields from others content types. In Hugo case, adding a complex content type based on hugo default features add a lot of content to frontmatter.json and make it unreadable. A easy solution should be to allow for content types to have a parent content type of which they inherit the fields. A more complex but adaptable solution should be to allow for content types to have multiple parents of which they inherit the fields. Here is the frontmatter.json extract for an mostly complete Hugo default content type to give you an idea of the length of a complete Hugo content type: ```json "frontMatter.taxonomy.contentTypes": [ { "name": "default", "previewPath": "", "pageBundle": false, "fields": [ { "title": "Title", "name": "title", "type": "string", "single": true }, { "title": "Link title", "name": "linkTitle", "type": "string", "single": true }, { "title": "Slug", "name": "slug", "type": "slug", "editable": true }, { "title": "URL", "name": "url", "type": "string", "single": true }, { "title": "Output formats", "name": "outputs", "type": "choice", "multiple": true, "choices": [ "", "HTML", "AMP", "CSS", "CSV", "Calendar", "JSON", "MARKDOWN", "ROBOTS", "RSS", "Sitemap", "WebAppManifest" ], "default": "", "hidden": true }, { "title": "Description", "name": "description", "type": "string", "single": false }, { "title": "Summary", "name": "summary", "type": "string", "single": false }, { "title": "Navigation weight", "name": "weight", "type": "number" }, { "title": "Is in draft", "name": "draft", "type": "draft", "default": true }, { "title": "Content date", "name": "date", "type": "datetime", "default": "{{now}}", "isPublishDate": false }, { "title": "Publishing date", "name": "publishDate", "type": "datetime", "default": "{{now}}", "isPublishDate": true }, { "title": "Expiration date", "name": "expiryDate", "type": "datetime", "default": null, "isPublishDate": false }, { "title": "Last modified date", "name": "lastmod", "type": "datetime", "default": "{{now}}", "isModifiedDate": true }, { "title": "Is headless bundle", "name": "headless", "type": "boolean", "default": false, "hidden": true }, { "title": "Image", "name": "images", "type": "image", "multiple": true, "isPreviewImage": true }, { "title": "Is CJK language", "name": "isCJKLanguage", "type": "boolean", "default": false, "hidden": true }, { "title": "Layout", "name": "layout", "type": "string", "single": true, "hidden": true }, { "title": "Aliases", "name": "aliases", "type": "list", "hidden": true }, { "title": "Categories", "name": "categories", "type": "categories" }, { "title": "Tags", "name": "tags", "type": "tags" }, { "title": "Audio", "name": "audio", "type": "list", "hidden": true }, { "title": "Videos", "name": "videos", "type": "list", "hidden": true }, { "title": "Content type", "name": "type", "type": "string", "single": true } ] } ] ``` <!-- github-sync-id:1376309963 -->
adam closed this issue 2026-10-05 02:41:13 +02:00
Author
Owner

This would definitely make maintaining content type definitions easier.

This would definitely make maintaining content type definitions easier. <!-- github-comment-id:1255002891 -->
Author
Owner

The fieldCollection field type supports this kind of functionality: https://frontmatter.codes/docs/content-creation/fields#fieldcollection

You can define the fields to re-use in other content types in the frontMatter.taxonomy.fieldGroups setting, and in your content type, all you need to do is use the fieldCollection field type. Front Mattter CMS will then automatically populate the content type with the fields you've defined in the field group.

The `fieldCollection` field type supports this kind of functionality: https://frontmatter.codes/docs/content-creation/fields#fieldcollection You can define the fields to re-use in other content types in the `frontMatter.taxonomy.fieldGroups` setting, and in your content type, all you need to do is use the `fieldCollection` field type. Front Mattter CMS will then automatically populate the content type with the fields you've defined in the field group. <!-- github-comment-id:2004436042 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/vscode-front-matter#334