From 109a6a592ddcca92ac4e76253c619008af95eac4 Mon Sep 17 00:00:00 2001 From: Ryan Watters Date: Mon, 27 Mar 2017 10:02:28 -0500 Subject: [PATCH] Move list and homepage content to list templates page Closes rdwatters/hugo-docs-concept#49 --- content/functions/findRe.md | 2 +- .../getting-started/directory-structure.md | 157 ------------------ content/templates/lists.md | 112 +++++++++++++ 3 files changed, 113 insertions(+), 158 deletions(-) diff --git a/content/functions/findRe.md b/content/functions/findRe.md index 2dc9e00fc..86109a1f9 100644 --- a/content/functions/findRe.md +++ b/content/functions/findRe.md @@ -33,7 +33,7 @@ You can limit the number of matches in the list with a third parameter. The foll ``` - + -
-
-
-

My Golang Journey

-
-

I decided to start learning Golang in March 2017.

-

Follow my journey through this new blog.

-
- -
- -``` -{{% /code %}} - -### List Pages Without `_index.md` - -You do *not* have to create an `_index.md` file for every list page (i.e. section, taxonomy, taxonomy terms, etc) or the homepage. If Hugo does not find an `_index.md` within the respective content section when rendering a [list template][lists], the page will be created but with no `{{.Content}}` and only the default values for `.Title` etc. - -Using this same `layouts/_default/list.html` template and applying it to the the `quotes` section above will render the following output. Note that `quotes` does not have an `_index.md` file to pull from: - -{{% code file="yoursite.com/quote/index.html" copy="false" %}} -```html - -
-
-
-

Quotes

-
-
- -
- -``` -{{% /code %}} - -{{% note %}} -The default behavior of Hugo is to pluralize list titles; hence the inflection of the `quote` section to "Quotes" when called with the `.Title` [page variable](/variables/page/). You can change this via the `pluralizeListTitles` directive in your [site configuration](/getting-started/configuration/). -{{% /note %}} - [archetypes]: /content-management/archetypes/ -[bepsays]: http://bepsays.com/en/2016/12/19/hugo-018/ [configuration directives]: /getting-started/configuration/#all-variables-yaml [`content`]: /content-management/organization/ [content section]: /content-management/sections/ diff --git a/content/templates/lists.md b/content/templates/lists.md index 4cd5dcc3f..bdb76289e 100644 --- a/content/templates/lists.md +++ b/content/templates/lists.md @@ -44,6 +44,117 @@ Since section lists and taxonomy lists (N.B., *not* [taxonomy terms lists][taxte 1. `layouts/_default/taxonomy.html` 2. `themes//layouts/_default/taxonomy.html` +## Adding Content to List Pages + +Since v0.18, [everything in Hugo is a `Page`][bepsays]. This means list pages and the homepage can have associated content files---i.e. `_index.md`---that contains page metadata (i.e., front matter) and content. This model allows you to include list-specific front matter via `.Params` and also means that list templates (e.g., `layouts/_default/list.html`) also have access to all [page variables][pagevars]. + +### Example Project Directory + +The following is an example of a typical Hugo project directory: + +```bash +. +├── config.toml +├── content +| ├── post +| | ├── _index.md +| | ├── post-01.md +| | └── post-02.md +| └── quote +| | ├── quote-01.md +| | └── quote-02.md +``` + +Using the above example, let's assume you have the following in `content/post/_index.md`: + +{{% code file="content/post/_index.md" %}} +```yaml +--- +title: My Golang Journey +date: 2017-03-23 +publishdate: 2017-03-24 +--- + +I decided to start learning Golang in March 2017. + +Follow my journey through this new blog. +``` +{{% /code %}} + +You can now access this `_index.md`'s' content in your list template: + +{{% code file="layouts/_default/list.html" %}} +```html +{{ define "main" }} +
+
+
+

{{.Title}}

+
+ {{.Content}} +
+ +
+{{ end }} +``` +{{% /code %}} + +This above will output the following HTML: + +{{% code file="yoursite.com/post/index.html" copy="false" %}} +```html + +
+
+
+

My Golang Journey

+
+

I decided to start learning Golang in March 2017.

+

Follow my journey through this new blog.

+
+ +
+ +``` +{{% /code %}} + +### List Pages Without `_index.md` + +You do *not* have to create an `_index.md` file for every list page (i.e. section, taxonomy, taxonomy terms, etc) or the homepage. If Hugo does not find an `_index.md` within the respective content section when rendering a [list template][lists], the page will be created but with no `{{.Content}}` and only the default values for `.Title` etc. + +Using this same `layouts/_default/list.html` template and applying it to the the `quotes` section above will render the following output. Note that `quotes` does not have an `_index.md` file to pull from: + +{{% code file="yoursite.com/quote/index.html" copy="false" %}} +```html + +
+
+
+

Quotes

+
+
+ +
+ +``` +{{% /code %}} + +{{% note %}} +The default behavior of Hugo is to pluralize list titles; hence the inflection of the `quote` section to "Quotes" when called with the `.Title` [page variable](/variables/page/). You can change this via the `pluralizeListTitles` directive in your [site configuration](/getting-started/configuration/). +{{% /note %}} + ## Example List Templates @@ -446,6 +557,7 @@ Using `first` and `where` together can be very powerful: {{% /code %}} +[bepsays]: http://bepsays.com/en/2016/12/19/hugo-018/ [directorystructure]: /getting-started/directory-structure/ [homepage]: /templates/homepage/ [homepage]: /templates/homepage/