2014-05-27 22:32:57 +00:00
|
|
|
|
---
|
2014-05-29 22:42:05 +00:00
|
|
|
|
aliases:
|
|
|
|
|
- /layout/indexes/
|
2016-01-06 22:45:19 +00:00
|
|
|
|
lastmod: 2015-08-04
|
2014-05-29 22:42:05 +00:00
|
|
|
|
date: 2013-07-01
|
2014-08-30 04:57:38 +00:00
|
|
|
|
linktitle: List of Content
|
2014-05-27 22:32:57 +00:00
|
|
|
|
menu:
|
|
|
|
|
main:
|
2014-05-29 22:42:05 +00:00
|
|
|
|
parent: layout
|
|
|
|
|
next: /templates/homepage
|
|
|
|
|
prev: /templates/content
|
|
|
|
|
title: Content List Template
|
|
|
|
|
weight: 40
|
2015-05-22 18:46:09 +00:00
|
|
|
|
toc: true
|
2014-05-27 22:32:57 +00:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
A list template is any template that will be used to render multiple pieces of
|
2015-01-28 02:17:09 +00:00
|
|
|
|
content in a single HTML page (with the exception of the [homepage](/layout/homepage/) which has a
|
2014-05-27 22:32:57 +00:00
|
|
|
|
dedicated template).
|
|
|
|
|
|
|
|
|
|
We are using the term list in its truest sense, a sequential arrangement
|
|
|
|
|
of material, especially in alphabetical or numerical order. Hugo uses
|
|
|
|
|
list templates to render anyplace where content is being listed such as
|
|
|
|
|
taxonomies and sections.
|
|
|
|
|
|
|
|
|
|
## Which Template will be rendered?
|
|
|
|
|
|
|
|
|
|
Hugo uses a set of rules to figure out which template to use when
|
|
|
|
|
rendering a specific page.
|
|
|
|
|
|
2014-09-03 04:12:26 +00:00
|
|
|
|
Hugo will use the following prioritized list. If a file isn’t present,
|
|
|
|
|
then the next one in the list will be used. This enables you to craft
|
2014-05-27 22:32:57 +00:00
|
|
|
|
specific layouts when you want to without creating more templates
|
2014-09-03 04:12:26 +00:00
|
|
|
|
than necessary. For most sites only the \_default file at the end of
|
2014-05-27 22:32:57 +00:00
|
|
|
|
the list will be needed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Section Lists
|
|
|
|
|
|
2015-01-29 19:34:56 +00:00
|
|
|
|
A Section will be rendered at /`SECTION`/ (e.g. http://spf13.com/project/)
|
2014-05-27 22:32:57 +00:00
|
|
|
|
|
|
|
|
|
* /layouts/section/`SECTION`.html
|
|
|
|
|
* /layouts/\_default/section.html
|
|
|
|
|
* /layouts/\_default/list.html
|
|
|
|
|
* /themes/`THEME`/layouts/section/`SECTION`.html
|
2014-11-23 05:31:52 +00:00
|
|
|
|
* /themes/`THEME`/layouts/\_default/section.html
|
2014-05-27 22:32:57 +00:00
|
|
|
|
* /themes/`THEME`/layouts/\_default/list.html
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Taxonomy Lists
|
|
|
|
|
|
2015-01-29 19:34:56 +00:00
|
|
|
|
A Taxonomy will be rendered at /`PLURAL`/`TERM`/ (e.g. http://spf13.com/topics/golang/) from:
|
2014-05-27 22:32:57 +00:00
|
|
|
|
|
2015-01-29 19:34:56 +00:00
|
|
|
|
* /layouts/taxonomy/`SINGULAR`.html (e.g. `/layouts/taxonomy/topic.html`)
|
2014-05-27 22:32:57 +00:00
|
|
|
|
* /layouts/\_default/taxonomy.html
|
|
|
|
|
* /layouts/\_default/list.html
|
|
|
|
|
* /themes/`THEME`/layouts/taxonomy/`SINGULAR`.html
|
2014-11-23 05:31:52 +00:00
|
|
|
|
* /themes/`THEME`/layouts/\_default/taxonomy.html
|
2014-05-27 22:32:57 +00:00
|
|
|
|
* /themes/`THEME`/layouts/\_default/list.html
|
|
|
|
|
|
|
|
|
|
### Section RSS
|
|
|
|
|
|
2015-01-29 19:34:56 +00:00
|
|
|
|
A Section’s RSS will be rendered at /`SECTION`/index.xml (e.g. http://spf13.com/project/index.xml)
|
2014-05-27 22:32:57 +00:00
|
|
|
|
|
2015-01-12 21:12:08 +00:00
|
|
|
|
*Hugo ships with its own [RSS 2.0][] template. In most cases this will
|
2014-09-03 04:12:26 +00:00
|
|
|
|
be sufficient, and an RSS template will not need to be provided by the
|
2014-05-27 22:32:57 +00:00
|
|
|
|
user.*
|
|
|
|
|
|
|
|
|
|
Hugo provides the ability for you to define any RSS type you wish, and
|
|
|
|
|
can have different RSS files for each section and taxonomy.
|
|
|
|
|
|
|
|
|
|
* /layouts/section/`SECTION`.rss.xml
|
|
|
|
|
* /layouts/\_default/rss.xml
|
|
|
|
|
* /themes/`THEME`/layouts/section/`SECTION`.rss.xml
|
|
|
|
|
* /themes/`THEME`/layouts/\_default/rss.xml
|
|
|
|
|
|
|
|
|
|
### Taxonomy RSS
|
|
|
|
|
|
2015-01-29 19:34:56 +00:00
|
|
|
|
A Taxonomy’s RSS will be rendered at /`PLURAL`/`TERM`/index.xml (e.g. http://spf13.com/topics/golang/index.xml)
|
2014-05-27 22:32:57 +00:00
|
|
|
|
|
2015-01-12 21:12:08 +00:00
|
|
|
|
*Hugo ships with its own [RSS 2.0][] template. In most cases this will
|
2014-09-03 04:12:26 +00:00
|
|
|
|
be sufficient, and an RSS template will not need to be provided by the
|
2014-05-27 22:32:57 +00:00
|
|
|
|
user.*
|
|
|
|
|
|
|
|
|
|
Hugo provides the ability for you to define any RSS type you wish, and
|
|
|
|
|
can have different RSS files for each section and taxonomy.
|
|
|
|
|
|
|
|
|
|
* /layouts/taxonomy/`SINGULAR`.rss.xml
|
|
|
|
|
* /layouts/\_default/rss.xml
|
|
|
|
|
* /themes/`THEME`/layouts/taxonomy/`SINGULAR`.rss.xml
|
|
|
|
|
* /themes/`THEME`/layouts/\_default/rss.xml
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Variables
|
|
|
|
|
|
2015-08-04 18:00:08 +00:00
|
|
|
|
List pages are of the type "node" and have all the [node variables](/templates/variables/)
|
|
|
|
|
and [site variables](/templates/variables/) available to use in the templates.
|
2014-05-27 22:32:57 +00:00
|
|
|
|
|
|
|
|
|
Taxonomy pages will additionally have:
|
|
|
|
|
|
2015-03-15 13:51:16 +00:00
|
|
|
|
**.Data.`Singular`** The taxonomy itself.<br>
|
2014-05-27 22:32:57 +00:00
|
|
|
|
|
|
|
|
|
## Example List Template Pages
|
|
|
|
|
|
|
|
|
|
### Example section template (post.html)
|
2015-01-28 02:17:09 +00:00
|
|
|
|
This content template is used for [spf13.com](http://spf13.com/).
|
|
|
|
|
It makes use of [partial templates](/templates/partials/). All examples use a
|
2014-05-27 22:32:57 +00:00
|
|
|
|
[view](/templates/views/) called either "li" or "summary" which this example site
|
|
|
|
|
defined.
|
|
|
|
|
|
2014-06-06 20:15:19 +00:00
|
|
|
|
{{ partial "header.html" . }}
|
|
|
|
|
{{ partial "subheader.html" . }}
|
2014-05-27 22:32:57 +00:00
|
|
|
|
|
|
|
|
|
<section id="main">
|
|
|
|
|
<div>
|
|
|
|
|
<h1 id="title">{{ .Title }}</h1>
|
|
|
|
|
<ul id="list">
|
|
|
|
|
{{ range .Data.Pages }}
|
|
|
|
|
{{ .Render "li"}}
|
|
|
|
|
{{ end }}
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
|
2015-01-16 09:33:20 +00:00
|
|
|
|
{{ partial "footer.html" . }}
|
2014-05-27 22:32:57 +00:00
|
|
|
|
|
|
|
|
|
### Example taxonomy template (tag.html)
|
2015-01-28 02:17:09 +00:00
|
|
|
|
This content template is used for [spf13.com](http://spf13.com/).
|
|
|
|
|
It makes use of [partial templates](/templates/partials/). All examples use a
|
2014-05-27 22:32:57 +00:00
|
|
|
|
[view](/templates/views/) called either "li" or "summary" which this example site
|
|
|
|
|
defined.
|
|
|
|
|
|
2014-06-06 20:15:19 +00:00
|
|
|
|
{{ partial "header.html" . }}
|
|
|
|
|
{{ partial "subheader.html" . }}
|
2014-05-27 22:32:57 +00:00
|
|
|
|
|
|
|
|
|
<section id="main">
|
|
|
|
|
<div>
|
|
|
|
|
<h1 id="title">{{ .Title }}</h1>
|
|
|
|
|
{{ range .Data.Pages }}
|
|
|
|
|
{{ .Render "summary"}}
|
|
|
|
|
{{ end }}
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
|
2015-01-16 09:33:20 +00:00
|
|
|
|
{{ partial "footer.html" . }}
|
2014-05-27 22:32:57 +00:00
|
|
|
|
|
|
|
|
|
## Ordering Content
|
|
|
|
|
|
2015-08-04 18:00:08 +00:00
|
|
|
|
In the case of Hugo, each list will render the content based on metadata provided in the [front
|
2015-01-28 02:17:09 +00:00
|
|
|
|
matter](/content/front-matter/). See [ordering content](/content/ordering/) for more information.
|
2014-05-27 22:32:57 +00:00
|
|
|
|
|
|
|
|
|
Here are a variety of different ways you can order the content items in
|
|
|
|
|
your list templates:
|
|
|
|
|
|
|
|
|
|
### Order by Weight -> Date (default)
|
|
|
|
|
|
|
|
|
|
{{ range .Data.Pages }}
|
|
|
|
|
<li>
|
|
|
|
|
<a href="{{ .Permalink }}">{{ .Title }}</a>
|
|
|
|
|
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
|
|
|
|
|
</li>
|
|
|
|
|
{{ end }}
|
|
|
|
|
|
|
|
|
|
### Order by Weight -> Date
|
|
|
|
|
|
|
|
|
|
{{ range .Data.Pages.ByWeight }}
|
|
|
|
|
<li>
|
|
|
|
|
<a href="{{ .Permalink }}">{{ .Title }}</a>
|
|
|
|
|
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
|
|
|
|
|
</li>
|
|
|
|
|
{{ end }}
|
|
|
|
|
|
|
|
|
|
### Order by Date
|
|
|
|
|
|
|
|
|
|
{{ range .Data.Pages.ByDate }}
|
|
|
|
|
<li>
|
|
|
|
|
<a href="{{ .Permalink }}">{{ .Title }}</a>
|
|
|
|
|
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
|
|
|
|
|
</li>
|
|
|
|
|
{{ end }}
|
|
|
|
|
|
2014-10-17 15:10:19 +00:00
|
|
|
|
### Order by PublishDate
|
|
|
|
|
|
|
|
|
|
{{ range .Data.Pages.ByPublishDate }}
|
|
|
|
|
<li>
|
|
|
|
|
<a href="{{ .Permalink }}">{{ .Title }}</a>
|
|
|
|
|
<div class="meta">{{ .PublishDate.Format "Mon, Jan 2, 2006" }}</div>
|
|
|
|
|
</li>
|
|
|
|
|
{{ end }}
|
2016-05-11 14:16:44 +00:00
|
|
|
|
|
|
|
|
|
### Order by ExpiryDate
|
|
|
|
|
|
|
|
|
|
{{ range .Data.Pages.ByExpiryDate }}
|
|
|
|
|
<li>
|
|
|
|
|
<a href="{{ .Permalink }}">{{ .Title }}</a>
|
|
|
|
|
<div class="meta">{{ .ExpiryDate.Format "Mon, Jan 2, 2006" }}</div>
|
|
|
|
|
</li>
|
|
|
|
|
{{ end }}
|
2016-04-22 18:46:04 +00:00
|
|
|
|
|
|
|
|
|
### Order by Lastmod
|
|
|
|
|
|
|
|
|
|
{{ range .Data.Pages.ByLastmod }}
|
|
|
|
|
<li>
|
|
|
|
|
<a href="{{ .Permalink }}">{{ .Title }}</a>
|
|
|
|
|
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
|
|
|
|
|
</li>
|
|
|
|
|
{{ end }}
|
2014-10-17 15:10:19 +00:00
|
|
|
|
|
2014-05-27 22:32:57 +00:00
|
|
|
|
### Order by Length
|
|
|
|
|
|
|
|
|
|
{{ range .Data.Pages.ByLength }}
|
|
|
|
|
<li>
|
|
|
|
|
<a href="{{ .Permalink }}">{{ .Title }}</a>
|
|
|
|
|
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
|
|
|
|
|
</li>
|
|
|
|
|
{{ end }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Order by Title
|
|
|
|
|
|
|
|
|
|
{{ range .Data.Pages.ByTitle }}
|
|
|
|
|
<li>
|
|
|
|
|
<a href="{{ .Permalink }}">{{ .Title }}</a>
|
|
|
|
|
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
|
|
|
|
|
</li>
|
|
|
|
|
{{ end }}
|
|
|
|
|
|
|
|
|
|
### Order by LinkTitle
|
|
|
|
|
|
|
|
|
|
{{ range .Data.Pages.ByLinkTitle }}
|
|
|
|
|
<li>
|
|
|
|
|
<a href="{{ .Permalink }}">{{ .LinkTitle }}</a>
|
|
|
|
|
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
|
|
|
|
|
</li>
|
|
|
|
|
{{ end }}
|
|
|
|
|
|
|
|
|
|
### Reverse Order
|
|
|
|
|
Can be applied to any of the above. Using Date for an example.
|
|
|
|
|
|
|
|
|
|
{{ range .Data.Pages.ByDate.Reverse }}
|
|
|
|
|
<li>
|
|
|
|
|
<a href="{{ .Permalink }}">{{ .Title }}</a>
|
|
|
|
|
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
|
|
|
|
|
</li>
|
|
|
|
|
{{ end }}
|
2014-08-27 13:50:06 +00:00
|
|
|
|
|
|
|
|
|
## Grouping Content
|
|
|
|
|
|
|
|
|
|
Hugo provides some grouping functions for list pages. You can use them to
|
2014-10-17 15:10:19 +00:00
|
|
|
|
group pages by Section, Type, Date etc.
|
2014-08-27 13:50:06 +00:00
|
|
|
|
|
|
|
|
|
Here are a variety of different ways you can group the content items in
|
|
|
|
|
your list templates:
|
|
|
|
|
|
|
|
|
|
### Grouping by Page field
|
|
|
|
|
|
2014-08-30 04:20:53 +00:00
|
|
|
|
{{ range .Data.Pages.GroupBy "Section" }}
|
2014-08-27 13:50:06 +00:00
|
|
|
|
<h3>{{ .Key }}</h3>
|
|
|
|
|
<ul>
|
2014-08-30 04:20:53 +00:00
|
|
|
|
{{ range .Pages }}
|
2014-08-27 13:50:06 +00:00
|
|
|
|
<li>
|
|
|
|
|
<a href="{{ .Permalink }}">{{ .Title }}</a>
|
|
|
|
|
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
|
|
|
|
|
</li>
|
|
|
|
|
{{ end }}
|
|
|
|
|
</ul>
|
|
|
|
|
{{ end }}
|
|
|
|
|
|
|
|
|
|
### Grouping by Page date
|
|
|
|
|
|
2014-08-30 04:20:53 +00:00
|
|
|
|
{{ range .Data.Pages.GroupByDate "2006-01" }}
|
2014-08-27 13:50:06 +00:00
|
|
|
|
<h3>{{ .Key }}</h3>
|
|
|
|
|
<ul>
|
2014-08-30 04:20:53 +00:00
|
|
|
|
{{ range .Pages }}
|
|
|
|
|
<li>
|
|
|
|
|
<a href="{{ .Permalink }}">{{ .Title }}</a>
|
|
|
|
|
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
|
|
|
|
|
</li>
|
|
|
|
|
{{ end }}
|
|
|
|
|
</ul>
|
|
|
|
|
{{ end }}
|
|
|
|
|
|
2014-10-17 15:10:19 +00:00
|
|
|
|
### Grouping by Page publish date
|
|
|
|
|
|
|
|
|
|
{{ range .Data.Pages.GroupByPublishDate "2006-01" }}
|
|
|
|
|
<h3>{{ .Key }}</h3>
|
|
|
|
|
<ul>
|
|
|
|
|
{{ range .Pages }}
|
|
|
|
|
<li>
|
|
|
|
|
<a href="{{ .Permalink }}">{{ .Title }}</a>
|
|
|
|
|
<div class="meta">{{ .PublishDate.Format "Mon, Jan 2, 2006" }}</div>
|
|
|
|
|
</li>
|
|
|
|
|
{{ end }}
|
|
|
|
|
</ul>
|
|
|
|
|
{{ end }}
|
|
|
|
|
|
|
|
|
|
### Grouping by Page param
|
|
|
|
|
|
|
|
|
|
{{ range .Data.Pages.GroupByParam "param_key" }}
|
|
|
|
|
<h3>{{ .Key }}</h3>
|
|
|
|
|
<ul>
|
|
|
|
|
{{ range .Pages }}
|
|
|
|
|
<li>
|
|
|
|
|
<a href="{{ .Permalink }}">{{ .Title }}</a>
|
|
|
|
|
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
|
|
|
|
|
</li>
|
|
|
|
|
{{ end }}
|
|
|
|
|
</ul>
|
|
|
|
|
{{ end }}
|
|
|
|
|
|
|
|
|
|
### Grouping by Page param in date format
|
|
|
|
|
|
|
|
|
|
{{ range .Data.Pages.GroupByParamDate "param_key" "2006-01" }}
|
|
|
|
|
<h3>{{ .Key }}</h3>
|
|
|
|
|
<ul>
|
|
|
|
|
{{ range .Pages }}
|
|
|
|
|
<li>
|
|
|
|
|
<a href="{{ .Permalink }}">{{ .Title }}</a>
|
|
|
|
|
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
|
|
|
|
|
</li>
|
|
|
|
|
{{ end }}
|
|
|
|
|
</ul>
|
|
|
|
|
{{ end }}
|
|
|
|
|
|
2014-08-30 04:20:53 +00:00
|
|
|
|
### Reversing Key Order
|
|
|
|
|
|
2015-08-04 18:00:08 +00:00
|
|
|
|
The ordering of the groups is performed by keys in alphanumeric order (A–Z,
|
2014-09-03 04:12:26 +00:00
|
|
|
|
1–100) and in reverse chronological order (newest first) for dates.
|
2014-08-30 04:20:53 +00:00
|
|
|
|
|
|
|
|
|
While these are logical defaults, they are not always the desired order. There
|
2015-08-04 18:00:08 +00:00
|
|
|
|
are two different syntaxes to change the order; they both work the same way, so
|
2014-08-30 04:20:53 +00:00
|
|
|
|
it’s really just a matter of preference.
|
|
|
|
|
|
|
|
|
|
#### Reverse method
|
|
|
|
|
|
|
|
|
|
{{ range (.Data.Pages.GroupBy "Section").Reverse }}
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
{{ range (.Data.Pages.GroupByDate "2006-01").Reverse }}
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### Providing the (alternate) direction
|
|
|
|
|
|
|
|
|
|
{{ range .Data.Pages.GroupByDate "2006-01" "asc" }}
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
{{ range .Data.Pages.GroupBy "Section" "desc" }}
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
### Ordering Pages within Group
|
|
|
|
|
|
2014-09-03 04:12:26 +00:00
|
|
|
|
Because Grouping returns a key and a slice of pages, all of the ordering methods listed above are available.
|
2014-08-30 04:20:53 +00:00
|
|
|
|
|
2015-08-04 18:00:08 +00:00
|
|
|
|
In this example, I’ve ordered the groups in chronological order and the content
|
2014-08-30 04:20:53 +00:00
|
|
|
|
within each group in alphabetical order by title.
|
|
|
|
|
|
|
|
|
|
{{ range .Data.Pages.GroupByDate "2006-01" "asc" }}
|
|
|
|
|
<h3>{{ .Key }}</h3>
|
|
|
|
|
<ul>
|
|
|
|
|
{{ range .Pages.ByTitle }}
|
2014-08-27 13:50:06 +00:00
|
|
|
|
<li>
|
|
|
|
|
<a href="{{ .Permalink }}">{{ .Title }}</a>
|
|
|
|
|
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
|
|
|
|
|
</li>
|
|
|
|
|
{{ end }}
|
|
|
|
|
</ul>
|
|
|
|
|
{{ end }}
|
2014-08-30 04:57:38 +00:00
|
|
|
|
|
|
|
|
|
## Filtering & Limiting Content
|
|
|
|
|
|
|
|
|
|
Sometimes you only want to list a subset of the available content. A common
|
2015-08-04 18:00:08 +00:00
|
|
|
|
request is to only display “Posts” on the homepage. Using the `where` function,
|
2014-08-30 04:57:38 +00:00
|
|
|
|
you can do just that.
|
|
|
|
|
|
2015-08-04 18:00:08 +00:00
|
|
|
|
### `first`
|
2014-08-30 04:57:38 +00:00
|
|
|
|
|
2014-09-03 04:12:26 +00:00
|
|
|
|
`first` works like the `limit` keyword in SQL. It reduces the array to only the
|
2015-08-04 18:00:08 +00:00
|
|
|
|
first _N_ elements. It takes the array and number of elements as input.
|
2014-08-30 04:57:38 +00:00
|
|
|
|
|
|
|
|
|
{{ range first 10 .Data.Pages }}
|
2015-08-04 18:00:08 +00:00
|
|
|
|
{{ .Render "summary" }}
|
2014-08-30 04:57:38 +00:00
|
|
|
|
{{ end }}
|
|
|
|
|
|
2015-08-04 18:00:08 +00:00
|
|
|
|
### `where`
|
2014-08-30 04:57:38 +00:00
|
|
|
|
|
2014-09-03 04:12:26 +00:00
|
|
|
|
`where` works in a similar manner to the `where` keyword in SQL. It selects all
|
2014-08-30 04:57:38 +00:00
|
|
|
|
elements of the slice that match the provided field and value. It takes three
|
2015-08-04 18:00:08 +00:00
|
|
|
|
arguments: 'array or slice of maps or structs', 'key or field name' and 'match
|
|
|
|
|
value'.
|
2014-08-30 04:57:38 +00:00
|
|
|
|
|
|
|
|
|
{{ range where .Data.Pages "Section" "post" }}
|
2015-08-04 18:00:08 +00:00
|
|
|
|
{{ .Content }}
|
2014-08-30 04:57:38 +00:00
|
|
|
|
{{ end }}
|
|
|
|
|
|
2015-08-04 18:00:08 +00:00
|
|
|
|
### `first` & `where` Together
|
2014-08-30 04:57:38 +00:00
|
|
|
|
|
|
|
|
|
Using both together can be very powerful.
|
|
|
|
|
|
|
|
|
|
{{ range first 5 (where .Data.Pages "Section" "post") }}
|
2015-08-04 18:00:08 +00:00
|
|
|
|
{{ .Content }}
|
2014-08-30 04:57:38 +00:00
|
|
|
|
{{ end }}
|
|
|
|
|
|
2015-08-04 18:00:08 +00:00
|
|
|
|
If `where` or `first` receives invalid input or a field name that doesn’t exist,
|
|
|
|
|
it will return an error and stop site generation.
|
2014-08-30 04:57:38 +00:00
|
|
|
|
|
|
|
|
|
These are both template functions and work on not only
|
|
|
|
|
[lists](/templates/list/), but [taxonomies](/taxonomies/displaying/),
|
|
|
|
|
[terms](/templates/terms/) and [groups](/templates/list/).
|
2015-01-12 21:12:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[RSS 2.0]: http://cyber.law.harvard.edu/rss/rss.html "RSS 2.0 Specification"
|