2017-08-10 11:18:22 -04:00
---
title: Archetypes
linktitle: Archetypes
2018-03-11 15:39:20 -04:00
description: Archetypes are templates used when creating new content.
2017-08-10 11:18:22 -04:00
date: 2017-02-01
publishdate: 2017-02-01
2017-09-21 13:03:00 -04:00
keywords: [archetypes,generators,metadata,front matter]
2017-08-10 11:18:22 -04:00
categories: ["content management"]
menu:
docs:
parent: "content-management"
weight: 70
quicklinks:
weight: 70 #rem
draft: false
aliases: [/content/archetypes/]
toc: true
---
## What are Archetypes?
2018-03-11 15:39:20 -04:00
**Archetypes** are content template files in the [archetypes directory][] of your project that contain preconfigured [front matter][] and possibly also a content disposition for your website's [content types][]. These will be used when you run `hugo new` .
2017-08-10 11:18:22 -04:00
2018-03-11 15:39:20 -04:00
The `hugo new` uses the `content-section` to find the most suitable archetype template in your project. If your project does not contain any archetype files, it will also look in the theme.
2017-08-10 11:18:22 -04:00
{{< code file = "archetype-example.sh" > }}
hugo new posts/my-first-post.md
{{< / code > }}
2018-03-11 15:39:20 -04:00
The above will create a new content file in `content/posts/my-first-post.md` using the first archetype file found of these:
2017-08-10 11:18:22 -04:00
1. `archetypes/posts.md`
2. `archetypes/default.md`
2018-03-11 15:39:20 -04:00
3. `themes/my-theme/posts.md`
4. `themes/my-theme/default.md`
2017-08-10 11:18:22 -04:00
2018-03-11 15:39:20 -04:00
The last two list items is only applicable if you use a theme and it uses the `my-theme` theme name as an example.
2017-08-10 11:18:22 -04:00
2018-03-11 15:39:20 -04:00
## Create a New Archetype Template
2017-08-10 11:18:22 -04:00
2018-03-11 15:39:20 -04:00
A fictional example for the section `newsletter` and the archetype file `archetypes/newsletter.md` . Create a new file in `archetypes/newsletter.md` and open it in a text editor.
2017-08-10 11:18:22 -04:00
2018-03-11 15:39:20 -04:00
{{< code file = "archetypes/newsletter.md" > }}
---
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: true
---
2017-08-10 11:18:22 -04:00
2018-03-11 15:39:20 -04:00
**Insert Lead paragraph here.**
2017-08-10 11:18:22 -04:00
2018-03-11 15:39:20 -04:00
## New Cool Posts
2017-08-10 11:18:22 -04:00
2018-03-11 15:39:20 -04:00
{{ range first 10 ( where .Site.RegularPages "Type" "cool" ) }}
* {{ .Title }}
{{ end }}
2017-08-10 11:18:22 -04:00
{{< / code > }}
2018-03-11 15:39:20 -04:00
When you create a new newsletter with:
2017-08-10 11:18:22 -04:00
2018-03-11 15:39:20 -04:00
```bash
hugo new newsletter/the-latest-cool.stuff.md
```
2017-08-10 11:18:22 -04:00
2018-03-11 15:39:20 -04:00
It will create a new newsletter type of content file based on the archetype template.
2017-08-10 11:18:22 -04:00
2018-03-11 15:39:20 -04:00
**Note:** the site will only be built if the `.Site` is in use in the archetype file, and this can be time consuming for big sites.
2017-08-10 11:18:22 -04:00
2018-03-11 15:39:20 -04:00
The above _newsletter type archetype_ illustrates the possibilities: The full Hugo `.Site` and all of Hugo' s template funcs can be used in the archetype file.
2017-08-10 11:18:22 -04:00
[archetypes directory]: /getting-started/directory-structure/
[content types]: /content-management/types/
[front matter]: /content-management/front-matter/