# Make frontmatter fields required per archetype / enforce schema?

**URL:** https://discourse.gohugo.io/t/make-frontmatter-fields-required-per-archetype-enforce-schema/33498
**Category:** support
**Created:** [June 21, 2021, 7:06pm UTC](https://discourse.gohugo.io/t/make-frontmatter-fields-required-per-archetype-enforce-schema/33498 "2021-06-21T19:06:17Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![helpwdh](https://avatars.discourse-cdn.com/v4/letter/h/2acd7d/32.png) [@helpwdh](https://discourse.gohugo.io/u/helpwdh)
#### Post date: [June 21, 2021, 7:06pm UTC](https://discourse.gohugo.io/t/make-frontmatter-fields-required-per-archetype-enforce-schema/33498/1 "2021-06-21T19:06:17Z")

</div>

I want to work with multiple editors to manage content with hugo. You can define an archetype, but this seems to only be for the initial creation of a document.

What I would like is the capability to define required frontmatter fields, and even better to tie them to a specific schema for validation. The goal would be that hugo refuses to build the site is a field is missing or its the wrong type/format.

I plan to automate this flow, at least server side, so if here is another tool I could run that would enforce the schema that would work for this need. I’ve seen some tools like NetlifyCMS where this enforcement could go into the gui, but I would like a way to do this without a dependency on a specific front end and on the server side.

Even some rudimentary required field functionality would be great.

---

<div class="post-metadata">

### Author: ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)
#### Post date: [June 21, 2021, 8:10pm UTC](https://discourse.gohugo.io/t/make-frontmatter-fields-required-per-archetype-enforce-schema/33498/2 "2021-06-21T20:10:46Z")

</div>

Let’s say your content looks like this:

```nohighlight
content/
├── article/
│ ├── article-1.md
│ ├── article-2.md
│ ├── article-3.md
│ └── _index.md
└── _index.md

```

And you want to validate the frontmatter in article-1, article-2, and article-3.

layouts/\_default/baseof.html

```auto
{{ if and (eq .Kind "page") (eq .Type "article") }}
  {{ partial "validate-article-params.html" . }}
{{ end }}

```

layouts/partials/validate-article-params.html

```auto
{{ $page := .}}
{{ $pageParams := slice
  (dict
    "name" "foo"
    "required" true
    "type" "string"
  )
  (dict
    "name" "bar"
    "required" false
    "type" "int64"
  )
  (dict
    "name" "baz"
    "required" false
    "type" "bool"
  )
}}
{{ range $pageParams }}
  {{ if .required }}
    {{ if not (isset $page.Params .name) }}
      {{ errorf "The %s parameter in %s is not defined." .name $page.Path }}
    {{ end }}
  {{ end }}
  {{ if isset $page.Params .name }}
    {{ $type := printf "%T" (index $page.Params .name) }}
    {{ if not (eq $type .type) }}
      {{ errorf "The %s parameter in %s is of type %s but should be of type %s." .name $page.Path $type .type }}
    {{ end }}
  {{ end }}
{{ end }}

```

See [https://gohugo.io/functions/errorf/](https://gohugo.io/functions/errorf/)
