Describe the use of custom archetypes in the docs

This commit is contained in:
digitalcraftsman 2015-08-24 13:29:45 +02:00 committed by spf13
parent 16cbda979c
commit d584ca59f0

View file

@ -56,8 +56,35 @@ Hugo would create the file with the following contents:
We see that the `title` and `date` variables have been added, in addition to the `tags` and `categories` variables which were carried over from `archetype/default.md`.
Congratulations! We have successfully created an archetype and used it for our new contents. That's all there is to it!
Congratulations! We have successfully created an archetype and used it for our new contents. But wait, what if I want to have different variables for another content type, like musicians? No problem.
### Creating custom archetypes
Earlier you created a new content type by adding a new subfolder to the content directory. In our case it's name would be `content/musician`. To use the corresponding archetype you just need to create a file named after the content type called `musician.md` in the `archetypes` directory, similar to the one below.
#### archetypes/musician.md
+++
name = ""
bio = ""
genre = ""
+++
Now let's create a new musician.
$ hugo new musician/mozart.md
This time, Hugo recognizes the custom archetype and uses it instead of the default one. So the generated file's frontmatter now includes the variables `name`, `bio` and `genre`.
#### content/musician/mozart.md
+++
title = "mozart"
date = "2015-08-24T13:04:37+02:00"
name = ""
bio = ""
genre = ""
+++
## Using a different front matter format