HUGO

  • News
  • Docs
  • Themes
  • Showcase
  • Community
  • GitHub
Star

What's on this Page

    • What are Archetypes?
    • Create a New Archetype Template
    • Directory based archetypes
CONTENT MANAGEMENT

Archetypes

Archetypes are templates used when creating new content.

What are Archetypes?

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.

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.

archetype-example.sh

hugo new posts/my-first-post.md

The above will create a new content file in content/posts/my-first-post.md using the first archetype file found of these:

  1. archetypes/posts.md
  2. archetypes/default.md
  3. themes/my-theme/archetypes/posts.md
  4. themes/my-theme/archetypes/default.md

The last two list items are only applicable if you use a theme and it uses the my-theme theme name as an example.

Create a New Archetype Template

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.

archetypes/newsletter.md

---
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: true
---

**Insert Lead paragraph here.****

## New Cool Posts

{{ range first 10 ( where .Site.RegularPages "Type" "cool" ) }}
* {{ .Title }}
{{ end }}

When you create a new newsletter with:

hugo new newsletter/the-latest-cool.stuff.md

It will create a new newsletter type of content file based on the archetype template.

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.

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.

Directory based archetypes

Since Hugo 0.49 you can use complete directories as archetype templates. Given this archetype directory:

archetypes
├── default.md
└── post-bundle
    ├── bio.md
    ├── images
    │   └── featured.jpg
    └── index.md
hugo new --kind post-bundle post/my-post

Will create a new folder in /content/post/my-post with the same set of files as in the post-bundle archetypes folder. All content files (index.md etc.) can contain template logic, and will receive the correct .Site for the content’s language.

See Also

  • Front Matter
  • Taxonomy Templates
  • Taxonomies
  • .Param
  • About Hugo
    • Overview
    • Hugo and GDPR
    • Hugo 0.32 HOWTO
    • What is Hugo
    • Hugo Features
    • The Benefits of Static
    • License
  • Getting Started
    • Get Started Overview
    • Quick Start
    • Install Hugo
    • Basic Usage
    • Directory Structure
    • Configuration
  • Themes
    • Themes Overview
    • Install and Use Themes
    • Theme Components
    • Create a Theme
  • Content Management
    • Content Management Overview
    • Organization
    • Page Bundles
    • Supported Content Formats
    • Front Matter
    • Page Resources
    • Image Processing
    • Shortcodes
    • Related Content
    • Sections
    • Types
    • Archetypes
    • Taxonomies
    • Summaries
    • Links and Cross References
    • URL Management
    • Menus
    • Static Files
    • Table of Contents
    • Comments
    • Multilingual and i18n
    • Syntax Highlighting
  • Templates
    • Templates Overview
    • Introduction
    • Template Lookup Order
    • Custom Output Formats
    • Base Templates and Blocks
    • List Page Templates
    • Homepage Template
    • Section Templates
    • Taxonomy Templates
    • Single Page Templates
    • Content View Templates
    • Data Templates
    • Partial Templates
    • Shortcode Templates
    • Local File Templates
    • 404 Page
    • Menu Templates
    • Pagination
    • RSS Templates
    • Sitemap Template
    • Robots.txt
    • Internal Templates
    • Alternative Templating
    • Template Debugging
  • Functions
    • Functions Quick Reference
    • Built-in
    • Cast
    • Collections
    • Compare
    • Crypto
    • Data
    • Encoding
    • Fmt
    • Hugo
    • Images
    • Inflect
    • Lang
    • Math
    • OS
    • Partials
    • Path
    • Reflect
    • Resources
    • Safe
    • Site
    • Strings
    • Templates
    • Time
    • Transform
    • URLs
  • Objects
    • Objects Overview
    • Site Objects
    • Page Objects
    • Shortcode Objects
    • Time Objects
    • Taxonomy Objects
    • File Objects
    • Menu Entry Objects
    • Hugo Objects
    • Git Objects
    • Sitemap Objects
  • Hugo Pipes
    • Hugo Pipes Overview
    • Hugo Pipes Introduction
    • SASS / SCSS
    • PostCSS
    • Asset minification
    • Asset bundling
    • Fingerprinting and SRI
    • Resource from Template
    • Resource from String
  • CLI
  • Troubleshooting
    • Troubleshoot
    • FAQ
    • Build Performance
  • Tools
    • Developer Tools Overview
    • Migrations
    • Starter Kits
    • Frontends
    • Editor Plug-ins
    • Search
    • Other Projects
  • Hosting & Deployment
    • Hosting & Deployment Overview
    • Host-Agnostic Deploys with Nanobox
    • Host on Netlify
    • Host on Firebase
    • Host on GitHub
    • Host on GitLab
    • Hosting on KeyCDN
    • Host on Bitbucket
    • Deployment with Wercker
    • Deployment with Rsync
  • Contribute
    • Contribute to Hugo
    • Development
    • Documentation
    • Themes
  • Maintenance
“Archetypes” was last updated: September 24, 2018: docs: Document directory based archetypes (2966f625)
Improve this page
By the Hugo Authors
Hugo Logo
  • File an Issue
  • Get Help
  • Discuss Source Code
  • @GoHugoIO
  • @spf13
  • @bepsays

 
  Hugo Sponsors
Logo for Forestry.io
Logo for Linode
Logo for eSolia
 

The Hugo logos are copyright © Steve Francia 2013–2019.

The Hugo Gopher is based on an original work by Renée French.

  • News
  • Docs
  • Themes
  • Showcase
  • Community
  • GitHub
  • About Hugo
  • Getting Started
  • Themes
  • Content Management
  • Templates
  • Functions
  • Objects
  • Hugo Pipes
  • CLI
  • Troubleshooting
  • Tools
  • Hosting & Deployment
  • Contribute
  • Maintenance