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.