mirror of
https://github.com/tiennm99/hugoDocs.git
synced 2026-10-14 12:16:55 +00:00
Update single page template example
Closes rdwatters/hugo-docs-concept#69
This commit is contained in:
1 parent
bd40c73f29
commit
8f60e9ace1
2 files changed
+11
-56
No files matched your search
@@ -43,11 +43,11 @@ Hugo assumes your content section and content type are the same unless you tell
|
|||||||
|
|
||||||
## Example Single Page Templates
|
## Example Single Page Templates
|
||||||
|
|
||||||
Content pages are of the type `page` and will therefore have all the [page variables][] and [site variables][] available to use in their templates.
|
Content pages are of the type `page` and will therefore have all the [page variables][pagevars] and [site variables][] available to use in their templates.
|
||||||
|
|
||||||
### `post/single.html`
|
### `post/single.html`
|
||||||
|
|
||||||
This single page template is a modified version of one used for for [spf13.com][spf13]. It makes use of [base templates][]:
|
This single page template makes use of Hugo [base templates][], the [`.Format` function][] for dates, the [`.WordCount` page variable][pagevars], and ranges through the single content's specific [taxonomies][pagetaxonomy]. [`with`][] is also used to check whether the taxonomies are set in the front matter.
|
||||||
|
|
||||||
{{% code file="layouts/post/single.html" download="single.html" %}}
|
{{% code file="layouts/post/single.html" download="single.html" %}}
|
||||||
```html
|
```html
|
||||||
@@ -64,7 +64,7 @@ This single page template is a modified version of one used for for [spf13.com][
|
|||||||
<div>
|
<div>
|
||||||
<section>
|
<section>
|
||||||
<h4 id="date"> {{ .Date.Format "Mon Jan 2, 2006" }} </h4>
|
<h4 id="date"> {{ .Date.Format "Mon Jan 2, 2006" }} </h4>
|
||||||
<h5 id="wc"> {{ .FuzzyWordCount }} Words </h5>
|
<h5 id="wordcount"> {{ .WordCount }} Words </h5>
|
||||||
</section>
|
</section>
|
||||||
{{ with .Params.topics }}
|
{{ with .Params.topics }}
|
||||||
<ul id="topics">
|
<ul id="topics">
|
||||||
@@ -82,10 +82,10 @@ This single page template is a modified version of one used for for [spf13.com][
|
|||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
{{ with .Prev }}
|
{{ with .PrevInSection }}
|
||||||
<a class="previous" href="{{.Permalink}}"> {{.Title}}</a>
|
<a class="previous" href="{{.Permalink}}"> {{.Title}}</a>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ with .Next }}
|
{{ with .NextInSection }}
|
||||||
<a class="next" href="{{.Permalink}}"> {{.Title}}</a>
|
<a class="next" href="{{.Permalink}}"> {{.Title}}</a>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
@@ -94,54 +94,6 @@ This single page template is a modified version of one used for for [spf13.com][
|
|||||||
```
|
```
|
||||||
{{% /code %}}
|
{{% /code %}}
|
||||||
|
|
||||||
### `project/single.html`
|
|
||||||
|
|
||||||
This single page template is also modified from an existing template for [spf13.com][spf13] and makes use of [base templates][]:
|
|
||||||
|
|
||||||
{{% code file="project/single.html" download="single.html" %}}
|
|
||||||
```html
|
|
||||||
{{ define "main" }}
|
|
||||||
<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>
|
|
||||||
{{ with .Params.topics }}
|
|
||||||
<ul id="topics">
|
|
||||||
{{ range . }}
|
|
||||||
<li><a href="{{ "topics" | absURL}}{{ . | urlize }}">{{ . }}</a> </li>
|
|
||||||
{{ end }}
|
|
||||||
</ul>
|
|
||||||
{{ end }}
|
|
||||||
{{ with .Params.tags}}
|
|
||||||
<ul id="tags">
|
|
||||||
{{ range . }}
|
|
||||||
<li> <a href="{{ "tags" | absURL }}{{ . | urlize}}">{{ . }}</a> </li>
|
|
||||||
{{ end }}
|
|
||||||
</ul>
|
|
||||||
{{ end }}
|
|
||||||
</div>
|
|
||||||
</aside>
|
|
||||||
{{with .Params "project_url" }}
|
|
||||||
<div id="ribbon">
|
|
||||||
<a href="{{ . }}">Fork me on GitHub</a>
|
|
||||||
</div>
|
|
||||||
{{ end }}
|
|
||||||
{{ end }}
|
|
||||||
```
|
|
||||||
{{% /code %}}
|
|
||||||
|
|
||||||
Notice how `project/single.html` uses an additional parameter unique to this template (i.e., `project_url`). This doesn't need to be defined ahead of time. The use of [`with`](/functions/with) means the key can be used in the template only if set in the content file's front matter.
|
|
||||||
|
|
||||||
To easily generate new instances of a content type (e.g., new `.md` files in a section like `project/`) with preconfigured front matter, use [content archetypes][archetypes].
|
To easily generate new instances of a content type (e.g., new `.md` files in a section like `project/`) with preconfigured front matter, use [content archetypes][archetypes].
|
||||||
|
|
||||||
[archetypes]: /content-management/archetypes/
|
[archetypes]: /content-management/archetypes/
|
||||||
@@ -150,9 +102,12 @@ To easily generate new instances of a content type (e.g., new `.md` files in a s
|
|||||||
[content type]: /content-management/types/
|
[content type]: /content-management/types/
|
||||||
[directory structure]: /getting-started/directory-structure/
|
[directory structure]: /getting-started/directory-structure/
|
||||||
[dry]: https://en.wikipedia.org/wiki/Don%27t_repeat_yourself
|
[dry]: https://en.wikipedia.org/wiki/Don%27t_repeat_yourself
|
||||||
|
[`.Format` function]: /functions/format/
|
||||||
[front matter]: /content-management/front-matter/
|
[front matter]: /content-management/front-matter/
|
||||||
[page variables]: /variables/page/
|
[pagetaxonomy]: /templates/taxonomy-templates/#displaying-a-single-piece-of-content-s-taxonomies
|
||||||
|
[pagevars]: /variables/page/
|
||||||
[partials]: /templates/partials/
|
[partials]: /templates/partials/
|
||||||
[section]: /content-management/sections/
|
[section]: /content-management/sections/
|
||||||
[site variables]: /variables/site/
|
[site variables]: /variables/site/
|
||||||
[spf13]: http://spf13.com/
|
[spf13]: http://spf13.com/
|
||||||
|
[`with`]: /functions/with/
|
||||||
@@ -203,7 +203,7 @@ using the [list templates](/templates/list/):
|
|||||||
3. You can list all terms for a taxonomy
|
3. You can list all terms for a taxonomy
|
||||||
4. You can list all taxonomies (with their terms)
|
4. You can list all taxonomies (with their terms)
|
||||||
|
|
||||||
### Displaying a Single Piece of Content's Taxonomies
|
## Displaying a Single Piece of Content's Taxonomies
|
||||||
|
|
||||||
Within your content templates, you may wish to display the taxonomies that piece of content is assigned to.
|
Within your content templates, you may wish to display the taxonomies that piece of content is assigned to.
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user