Create new page with different archetypes

I run command hugo new post/title.md to create a new page, and I need to create pages with different archetypes, such as hugo new post/title.md uses archetype default.md, and hugo new post/foo.md uses archetype bar.md.

How? Thank you.

Give this file tree:

ā”œā”€ā”€ archetypes
│   ā”œā”€ā”€ default.md
│   └── post.md
ā”œā”€ā”€ content
│   ā”œā”€ā”€ post
│   │   └── title.md
│   └── regular
│       └── title.md

Then running

hugo new regular/title.md

Will use this archetype

archetypes/default.md

And running

hugo new post/title.md

Will use this archetype

archetypes/post.md

You can also specify the archetype to be used while running hugo new.

Assuming you have this structure,

ā”œā”€ā”€ archetypes
│   ā”œā”€ā”€ default.md
│   ā”œā”€ā”€ post.md
│   └── page.md
ā”œā”€ā”€ content
│   ā”œā”€ā”€ pages
│   │   └── page1.md
│   └── posts
│       └── post1.md

You can use the -k flag like this to create new files with a specific archetype:

hugo new -k post posts/post2.md
hugo new -k page pages/page2.md
1 Like

Thank you.

Thank you too.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.