Pre-defined categories and tags

Is there a way to pre-define the categories and tags that can be used in the front-matter of content? I am specifically interested in allowing users to add only one category per content and then use only those tags that have been pre-defined in the config.toml.

Hi,

I don’t think that feature is available. What can be done though is to have default values for tags/categories pre-populated when you hugo new ... by using archetypes. And then in your layouts maybe conditionally display only the tags/categories that are allowed.

2 Likes

Would this be of interest? If yes, I could try to work on it. Could someone give me some pointers on what approach to take?

Well, the markdown files are just text files, so a user can type anything he wants. The only way to gain control is to not let the user write the hugo page directly but through some kind of CMS. Then you could generate the front matter with a form and use JavaScript to let the user select from predefined values. So it’s not something directly related to Hugo.

I used a workaround by counting the number of categories in single.html and then using errorf.

  {{ $numCategories := len .Params.categories }}
  {{ if ge $numCategories 2 }}
      {{ errorf "At least one post (%q) has more than one category." .Path }}
  {{ end }}