mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Describe the use of custom archetypes in the docs
This commit is contained in:
parent
16cbda979c
commit
d584ca59f0
1 changed files with 28 additions and 1 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue