2013-08-17 12:34:25 +00:00
|
|
|
|
---
|
2014-05-29 22:42:05 +00:00
|
|
|
|
aliases:
|
2014-11-30 16:42:14 +00:00
|
|
|
|
- /layout/content/
|
2016-01-06 22:45:19 +00:00
|
|
|
|
lastmod: 2015-05-22
|
2014-05-29 22:42:05 +00:00
|
|
|
|
date: 2013-07-01
|
2014-08-30 04:57:38 +00:00
|
|
|
|
linktitle: Single Content
|
2014-04-23 07:00:11 +00:00
|
|
|
|
menu:
|
|
|
|
|
main:
|
2014-05-29 22:42:05 +00:00
|
|
|
|
parent: layout
|
|
|
|
|
next: /templates/list
|
|
|
|
|
prev: /templates/variables
|
|
|
|
|
title: Single Content Template
|
|
|
|
|
weight: 30
|
2015-05-22 18:46:09 +00:00
|
|
|
|
toc: true
|
2013-08-17 12:34:25 +00:00
|
|
|
|
---
|
|
|
|
|
|
2014-09-03 04:12:26 +00:00
|
|
|
|
The primary view of content in Hugo is the single view. Hugo, for every
|
|
|
|
|
Markdown file provided, will render it with a single template.
|
2014-05-27 22:32:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 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
|
2015-01-28 02:17:09 +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.
|
|
|
|
|
|
2015-01-28 02:17:09 +00:00
|
|
|
|
Users can specify the `type` and `layout` in the [front-matter](/content/front-matter/). `Section`
|
2016-04-28 16:32:13 +00:00
|
|
|
|
is determined based on the content file’s location. If `type` is provided,
|
2014-05-27 22:32:57 +00:00
|
|
|
|
it will be used instead of `section`.
|
|
|
|
|
|
|
|
|
|
### Single
|
|
|
|
|
|
2014-08-03 10:53:48 +00:00
|
|
|
|
* /layouts/`TYPE`-or-`SECTION`/`LAYOUT`.html
|
|
|
|
|
* /layouts/`TYPE`-or-`SECTION`/single.html
|
2014-05-27 22:32:57 +00:00
|
|
|
|
* /layouts/\_default/single.html
|
2014-08-03 10:53:48 +00:00
|
|
|
|
* /themes/`THEME`/layouts/`TYPE`-or-`SECTION`/`LAYOUT`.html
|
|
|
|
|
* /themes/`THEME`/layouts/`TYPE`-or-`SECTION`/single.html
|
2014-05-27 22:32:57 +00:00
|
|
|
|
* /themes/`THEME`/layouts/\_default/single.html
|
|
|
|
|
|
|
|
|
|
## Example Single Template File
|
2013-08-17 12:34:25 +00:00
|
|
|
|
|
|
|
|
|
Content pages are of the type "page" and have all the [page
|
2014-05-27 22:32:57 +00:00
|
|
|
|
variables](/layout/variables/) and [site
|
|
|
|
|
variables](/templates/variables/) available to use in the templates.
|
2013-08-17 12:34:25 +00:00
|
|
|
|
|
|
|
|
|
In the following examples we have created two different content types as well as
|
|
|
|
|
a default content type.
|
|
|
|
|
|
2014-05-27 22:32:57 +00:00
|
|
|
|
The default content template to be used in the event that a specific
|
|
|
|
|
template has not been provided for that type. The default type works the
|
2014-09-03 04:12:26 +00:00
|
|
|
|
same as the other types, but the directory must be called "\_default".
|
2014-05-27 22:32:57 +00:00
|
|
|
|
|
2013-08-17 12:34:25 +00:00
|
|
|
|
▾ layouts/
|
2014-05-27 22:32:57 +00:00
|
|
|
|
▾ _default/
|
|
|
|
|
single.html
|
2013-08-17 12:34:25 +00:00
|
|
|
|
▾ post/
|
|
|
|
|
single.html
|
|
|
|
|
▾ project/
|
|
|
|
|
single.html
|
|
|
|
|
|
|
|
|
|
|
2015-05-22 18:46:09 +00:00
|
|
|
|
### post/single.html
|
2015-01-28 02:17:09 +00:00
|
|
|
|
This content template is used for [spf13.com](http://spf13.com/).
|
2015-02-14 20:20:06 +00:00
|
|
|
|
It makes use of [partial templates](/templates/partials/)
|
2013-08-17 12:34:25 +00:00
|
|
|
|
|
2014-06-06 20:15:19 +00:00
|
|
|
|
{{ partial "header.html" . }}
|
|
|
|
|
{{ partial "subheader.html" . }}
|
2015-03-18 06:44:12 +00:00
|
|
|
|
{{ $baseurl := .Site.BaseURL }}
|
2013-08-17 12:34:25 +00:00
|
|
|
|
|
|
|
|
|
<section id="main">
|
|
|
|
|
<h1 id="title">{{ .Title }}</h1>
|
|
|
|
|
<div>
|
|
|
|
|
<article id="content">
|
|
|
|
|
{{ .Content }}
|
|
|
|
|
</article>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<aside id="meta">
|
|
|
|
|
<div>
|
|
|
|
|
<section>
|
|
|
|
|
<h4 id="date"> {{ .Date.Format "Mon Jan 2, 2006" }} </h4>
|
|
|
|
|
<h5 id="wc"> {{ .FuzzyWordCount }} Words </h5>
|
|
|
|
|
</section>
|
|
|
|
|
<ul id="categories">
|
|
|
|
|
{{ range .Params.topics }}
|
|
|
|
|
<li><a href="{{ $baseurl }}/topics/{{ . | urlize }}">{{ . }}</a> </li>
|
|
|
|
|
{{ end }}
|
|
|
|
|
</ul>
|
|
|
|
|
<ul id="tags">
|
|
|
|
|
{{ range .Params.tags }}
|
|
|
|
|
<li> <a href="{{ $baseurl }}/tags/{{ . | urlize }}">{{ . }}</a> </li>
|
|
|
|
|
{{ end }}
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
2013-08-20 16:13:27 +00:00
|
|
|
|
{{ if .Prev }}
|
|
|
|
|
<a class="previous" href="{{.Prev.Permalink}}"> {{.Prev.Title}}</a>
|
|
|
|
|
{{ end }}
|
|
|
|
|
{{ if .Next }}
|
|
|
|
|
<a class="next" href="{{.Next.Permalink}}"> {{.Next.Title}}</a>
|
|
|
|
|
{{ end }}
|
2013-08-17 12:34:25 +00:00
|
|
|
|
</div>
|
|
|
|
|
</aside>
|
|
|
|
|
|
2014-06-06 20:15:19 +00:00
|
|
|
|
{{ partial "disqus.html" . }}
|
|
|
|
|
{{ partial "footer.html" . }}
|
2013-08-17 12:34:25 +00:00
|
|
|
|
|
|
|
|
|
|
2015-05-22 18:46:09 +00:00
|
|
|
|
### project/single.html
|
2015-01-28 02:17:09 +00:00
|
|
|
|
This content template is used for [spf13.com](http://spf13.com/).
|
2015-02-14 20:08:50 +00:00
|
|
|
|
It makes use of [partial templates](/templates/partials/)
|
2013-08-17 12:34:25 +00:00
|
|
|
|
|
|
|
|
|
|
2014-06-06 20:15:19 +00:00
|
|
|
|
{{ partial "header.html" . }}
|
|
|
|
|
{{ partial "subheader.html" . }}
|
2015-03-18 06:44:12 +00:00
|
|
|
|
{{ $baseurl := .Site.BaseURL }}
|
2013-08-17 12:34:25 +00:00
|
|
|
|
|
|
|
|
|
<section id="main">
|
|
|
|
|
<h1 id="title">{{ .Title }}</h1>
|
|
|
|
|
<div>
|
|
|
|
|
<article id="content">
|
|
|
|
|
{{ .Content }}
|
|
|
|
|
</article>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<aside id="meta">
|
|
|
|
|
<div>
|
|
|
|
|
<section>
|
|
|
|
|
<h4 id="date"> {{ .Date.Format "Mon Jan 2, 2006" }} </h4>
|
|
|
|
|
<h5 id="wc"> {{ .FuzzyWordCount }} Words </h5>
|
|
|
|
|
</section>
|
|
|
|
|
<ul id="categories">
|
|
|
|
|
{{ range .Params.topics }}
|
|
|
|
|
<li><a href="{{ $baseurl }}/topics/{{ . | urlize }}">{{ . }}</a> </li>
|
|
|
|
|
{{ end }}
|
|
|
|
|
</ul>
|
|
|
|
|
<ul id="tags">
|
|
|
|
|
{{ range .Params.tags }}
|
|
|
|
|
<li> <a href="{{ $baseurl }}/tags/{{ . | urlize }}">{{ . }}</a> </li>
|
|
|
|
|
{{ end }}
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
</aside>
|
|
|
|
|
|
|
|
|
|
{{if isset .Params "project_url" }}
|
|
|
|
|
<div id="ribbon">
|
|
|
|
|
<a href="{{ index .Params "project_url" }}" rel="me">Fork me on GitHub</a>
|
|
|
|
|
</div>
|
|
|
|
|
{{ end }}
|
|
|
|
|
|
2015-01-31 14:27:42 +00:00
|
|
|
|
{{ partial "footer.html" . }}
|
2013-08-17 12:34:25 +00:00
|
|
|
|
|
|
|
|
|
Notice how the project/single.html template uses an additional parameter unique
|
|
|
|
|
to this template. This doesn't need to be defined ahead of time. If the key is
|
2014-05-27 22:32:57 +00:00
|
|
|
|
present in the front matter than it can be used in the template. To
|
|
|
|
|
easily generate new content of this type with these keys ready use
|
2015-01-28 02:17:09 +00:00
|
|
|
|
[content archetypes](/content/archetypes/).
|