Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commands, create: Add .Site to the archetype templates #3607

Merged
merged 1 commit into from
Jun 19, 2017

Conversation

bep
Copy link
Member

@bep bep commented Jun 18, 2017

This commit completes the "The Revival of the Archetypes!"

If .Site is used in the arcetype template, the site is built and added to the template context.

Note that this may be potentially time consuming for big sites.

A more complete example would then be for the section newsletter and the archetype file archetypes/newsletter.md:

---
title: "{{ replace .TranslationBaseName "-" " " | title }}"
date: {{ .Date }}
tags:
- x
categories:
- x
draft: true
---

<!--more-->

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

And then create a new post with:

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

Hot Tip: If you set the newContentEditor configuration variable to an editor on your PATH, the newly created article will be opened.

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.

Fixes #1629

@bep bep force-pushed the archetypesite branch 2 times, most recently from 3520425 to 37eb4d2 Compare June 19, 2017 08:19
This commit completes the "The Revival of the Archetypes!"

If `.Site` is used in the arcetype template, the site is built and added to the template context.

Note that this may be potentially time consuming for big sites.

A more complete example would then be for the section `newsletter` and the archetype file `archetypes/newsletter.md`:

```
---
title: "{{ replace .TranslationBaseName "-" " " | title }}"
date: {{ .Date }}
tags:
- x
categories:
- x
draft: true
---

<!--more-->

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

And then create a new post with:

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

**Hot Tip:** If you set the `newContentEditor` configuration variable to an editor on your `PATH`, the newly created article will be opened.

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.

Fixes gohugoio#1629
@bep bep changed the title WIP commands, create: Add .Site to the archetype templates commands, create: Add .Site to the archetype templates Jun 19, 2017
@bep bep merged commit 662e12f into gohugoio:master Jun 19, 2017
@bep
Copy link
Member Author

bep commented Jun 19, 2017

For docs on "what vars can I use in the archetype template", see ArchetypeFileData here:

https://godoc.org/github.com/gohugoio/hugo/create

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add .Site to archetypes templating
1 participant