mirror of
https://github.com/gohugoio/hugo.git
synced 2025-05-08 11:47:34 +03:00
Merge commit 'ec4e6f9df2
' as 'docs'
This commit is contained in:
commit
a1900826b9
839 changed files with 44703 additions and 0 deletions
23
docs/content/variables/_index.md
Normal file
23
docs/content/variables/_index.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
---
|
||||
title: Variables and Params
|
||||
linktitle: Variables Overview
|
||||
description: Page-, file-, taxonomy-, and site-level variables and parameters available in templates.
|
||||
date: 2017-02-01
|
||||
publishdate: 2017-02-01
|
||||
lastmod: 2017-02-01
|
||||
categories: [variables and params]
|
||||
#tags: [variables,params,values,globals]
|
||||
draft: false
|
||||
menu:
|
||||
docs:
|
||||
parent: "variables"
|
||||
weight: 1
|
||||
weight: 01 #rem
|
||||
sections_weight: 01
|
||||
aliases: [/templates/variables/]
|
||||
toc: false
|
||||
---
|
||||
|
||||
Hugo's templates are context aware and make a large number of values available to you as you're creating views for your website.
|
||||
|
||||
[Go templates]: /templates/introduction/ "Understand context in Go templates by learning the language's fundamental templating functions."
|
48
docs/content/variables/files.md
Normal file
48
docs/content/variables/files.md
Normal file
|
@ -0,0 +1,48 @@
|
|||
---
|
||||
title: File Variables
|
||||
linktitle:
|
||||
description: "You can access filesystem-related data for a content file in the `.File` variable."
|
||||
date: 2017-02-01
|
||||
publishdate: 2017-02-01
|
||||
lastmod: 2017-02-01
|
||||
categories: [variables and params]
|
||||
#tags: [files]
|
||||
draft: false
|
||||
menu:
|
||||
docs:
|
||||
parent: "variables"
|
||||
weight: 40
|
||||
weight: 40
|
||||
sections_weight: 40
|
||||
aliases: [/variables/file-variables/]
|
||||
toc: false
|
||||
---
|
||||
|
||||
{{% note "Rendering Local Files" %}}
|
||||
For information on creating shortcodes and templates that tap into Hugo's file-related feature set, see [Local File Templates](/templates/files/).
|
||||
{{% /note %}}
|
||||
|
||||
The `.File` object contains the following fields:
|
||||
|
||||
`.File.Path`
|
||||
: the original relative path of the page (e.g., `content/posts/foo.en.md`)
|
||||
|
||||
`.File.LogicalName`
|
||||
: the name of the content file that represents a page (e.g., `foo.en.md`)
|
||||
|
||||
`.File.TranslationBaseName`
|
||||
: the filename without extension or optional language identifier (e.g., `foo`)
|
||||
|
||||
`.File.BaseFileName`
|
||||
: the filename without extension (e.g., `foo.en`)
|
||||
|
||||
`.File.Ext`
|
||||
: the file extension of the content file (e.g., `md`); this can also be called using `.File.Extension` as well. Note that it is *only* the extension without `.`.
|
||||
|
||||
`.File.Lang`
|
||||
: the language associated with the given file if Hugo's [Multilingual features][multilingual] are enabled (e.g., `en`)
|
||||
|
||||
`.File.Dir`
|
||||
: given the path `content/posts/dir1/dir2/`, the relative directory path of the content file will be returned (e.g., `posts/dir1/dir2/`)
|
||||
|
||||
[Multilingual]: /content-management/multilingual/
|
54
docs/content/variables/git.md
Normal file
54
docs/content/variables/git.md
Normal file
|
@ -0,0 +1,54 @@
|
|||
---
|
||||
title: Git Info Variables
|
||||
linktitle: Git Variables
|
||||
description: Get the last Git revision information for every content file.
|
||||
date: 2017-03-12
|
||||
publishdate: 2017-03-12
|
||||
lastmod: 2017-03-12
|
||||
categories: [variables and params]
|
||||
#tags: [git]
|
||||
draft: false
|
||||
menu:
|
||||
docs:
|
||||
parent: "variables"
|
||||
weight: 70
|
||||
weight: 70
|
||||
sections_weight: 70
|
||||
aliases: [/extras/gitinfo/]
|
||||
toc: false
|
||||
wip: false
|
||||
---
|
||||
|
||||
{{% note "`.GitInfo` Performance Considerations" %}}
|
||||
Hugo's Git integrations should be fairly performant but *can* increase your build time. This will depend on the size of your Git history.
|
||||
{{% /note %}}
|
||||
|
||||
## `.GitInfo` Prerequisites
|
||||
|
||||
1. The Hugo site must be in a Git-enabled directory.
|
||||
2. The Git executable must be installed and in your system `PATH`.
|
||||
3. The `.GitInfo` feature must be enabled in your Hugo project by passing `--enableGitInfo` flag on the command line or by setting `enableGitInfo` to `true` in your [site's configuration file][configuration].
|
||||
|
||||
## The `.GitInfo` Object
|
||||
|
||||
The `GitInfo` object contains the following fields:
|
||||
|
||||
`.AbbreviatedHash`
|
||||
: the abbreviated commit hash (e.g., `866cbcc`)
|
||||
|
||||
`.AuthorName`
|
||||
: the author's name, respecting `.mailmap`
|
||||
|
||||
`.AuthorEmail`
|
||||
: the author's email address, respecting `.mailmap`
|
||||
|
||||
`.AuthorDate`
|
||||
: the author date
|
||||
|
||||
`.Hash`
|
||||
: the commit hash (e.g., `866cbccdab588b9908887ffd3b4f2667e94090c3`)
|
||||
|
||||
`.Subject`
|
||||
: commit message subject (e.g., `tpl: Add custom index function`)
|
||||
|
||||
[configuration]: /getting-started/configuration/
|
39
docs/content/variables/hugo.md
Normal file
39
docs/content/variables/hugo.md
Normal file
|
@ -0,0 +1,39 @@
|
|||
---
|
||||
title: Hugo-specific Variables
|
||||
linktitle: Hugo Variables
|
||||
description: The `.Hugo` variable provides easy access to Hugo-related data.
|
||||
date: 2017-03-12
|
||||
publishdate: 2017-03-12
|
||||
lastmod: 2017-03-12
|
||||
categories: [variables and params]
|
||||
#tags: [hugo,generator]
|
||||
draft: false
|
||||
menu:
|
||||
docs:
|
||||
parent: "variables"
|
||||
weight: 60
|
||||
weight: 60
|
||||
sections_weight: 60
|
||||
aliases: []
|
||||
toc: false
|
||||
wip: false
|
||||
---
|
||||
|
||||
It contains the following fields:
|
||||
|
||||
`.Hugo.Generator`
|
||||
: `<meta>` tag for the version of Hugo that generated the site. `.Hugo.Generator` outputs a *complete* HTML tag; e.g. `<meta name="generator" content="Hugo 0.18" />`
|
||||
|
||||
`.Hugo.Version`
|
||||
: the current version of the Hugo binary you are using e.g. `0.13-DEV`<br>
|
||||
|
||||
`.Hugo.CommitHash`
|
||||
: the git commit hash of the current Hugo binary e.g. `0e8bed9ccffba0df554728b46c5bbf6d78ae5247`
|
||||
|
||||
`.Hugo.BuildDate`
|
||||
: the compile date of the current Hugo binary formatted with RFC 3339 e.g. `2002-10-02T10:00:00-05:00`<br>
|
||||
|
||||
{{% note "Use the Hugo Generator Tag" %}}
|
||||
We highly recommend using `.Hugo.Generator` in your website's `<head>`. `.Hugo.Generator` is included by default in all themes hosted on [themes.gohugo.io](http://themes.gohugo.io). The generator tag allows the Hugo team to track the usage and popularity of Hugo.
|
||||
{{% /note %}}
|
||||
|
50
docs/content/variables/menus.md
Normal file
50
docs/content/variables/menus.md
Normal file
|
@ -0,0 +1,50 @@
|
|||
---
|
||||
title: Menu Variables
|
||||
linktitle: Menu Variables
|
||||
description: A menu entry in a menu template has specific variables and functions to make menu management easier.
|
||||
date: 2017-03-12
|
||||
publishdate: 2017-03-12
|
||||
lastmod: 2017-03-12
|
||||
categories: [variables and params]
|
||||
#tags: [menus]
|
||||
draft: false
|
||||
menu:
|
||||
docs:
|
||||
parent: "variables"
|
||||
weight: 50
|
||||
weight: 50
|
||||
sections_weight: 50
|
||||
aliases: [/variables/menu/]
|
||||
toc: false
|
||||
---
|
||||
|
||||
The [menu template][] has the following properties:
|
||||
|
||||
`.URL`
|
||||
: string
|
||||
|
||||
`.Name`
|
||||
: string
|
||||
|
||||
`.Menu`
|
||||
: string
|
||||
|
||||
`.Identifier`
|
||||
: string
|
||||
|
||||
`.Pre`
|
||||
: template.HTML
|
||||
|
||||
`.Post`
|
||||
: template.HTML
|
||||
|
||||
`.Weight`
|
||||
: int
|
||||
|
||||
`.Parent`
|
||||
: string
|
||||
|
||||
`.Children`
|
||||
: Menu
|
||||
|
||||
[menu template]: /templates/menu-templates/
|
268
docs/content/variables/page.md
Normal file
268
docs/content/variables/page.md
Normal file
|
@ -0,0 +1,268 @@
|
|||
---
|
||||
title: Page Variables
|
||||
linktitle:
|
||||
description: Page-level variables are defined in a content file's front matter, derived from the content's file location, or extracted from the content body itself.
|
||||
date: 2017-02-01
|
||||
publishdate: 2017-02-01
|
||||
lastmod: 2017-02-01
|
||||
categories: [variables and params]
|
||||
#tags: [pages]
|
||||
draft: false
|
||||
menu:
|
||||
docs:
|
||||
parent: "variables"
|
||||
weight: 20
|
||||
weight: 20
|
||||
sections_weight: 20
|
||||
aliases: [/variables/page/]
|
||||
toc: true
|
||||
---
|
||||
|
||||
The following is a list of page-level variables. Many of these will be defined in the front matter, derived from file location, or extracted from the content itself.
|
||||
|
||||
{{% note "`.Scratch`" %}}
|
||||
See [`.Scratch`](/functions/scratch/) for page-scoped, writable variables.
|
||||
{{% /note %}}
|
||||
|
||||
## Page Variables
|
||||
|
||||
`.AlternativeOutputFormats`
|
||||
: contains all alternative formats for a given page; this variable is especially useful `link rel` list in your site's `<head>`. (See [Output Formats](/templates/output-formats/).)
|
||||
|
||||
`.Content`
|
||||
: the content itself, defined below the front matter.
|
||||
|
||||
`.Data`
|
||||
: the data specific to this type of page.
|
||||
|
||||
`.Date`
|
||||
: the date associated with the page; `.Date` pulls from the `date` field in a content's front matter. See also `.ExpiryDate`, `.PublishDate`, and `.Lastmod`.
|
||||
|
||||
`.Description`
|
||||
: the description for the page.
|
||||
|
||||
`.Draft`
|
||||
: a boolean, `true` if the content is marked as a draft in the front matter.
|
||||
|
||||
`.ExpiryDate`
|
||||
: the date on which the content is scheduled to expire; `.ExpiryDate` pulls from the `expirydate` field in a content's front matter. See also `.PublishDate`, `.Date`, and `.Lastmod`.
|
||||
|
||||
`.FuzzyWordCount`
|
||||
: the approximate number of words in the content.
|
||||
|
||||
`.Hugo`
|
||||
: see [Hugo Variables](/variables/hugo/).
|
||||
|
||||
`.IsHome`
|
||||
: `true` in the context of the [homepage](/templates/homepage/).
|
||||
|
||||
`.IsNode`
|
||||
: always `false` for regular content pages.
|
||||
|
||||
`.IsPage`
|
||||
: always `true` for regular content pages.
|
||||
|
||||
`.IsTranslated`
|
||||
: `true` if there are translations to display.
|
||||
|
||||
`.Keywords`
|
||||
: the meta keywords for the content.
|
||||
|
||||
`.Kind`
|
||||
: the page's *kind*. Possible return values are `page`, `home`, `section`, `taxonomy`, or `taxonomyTerm`. Note that there are also `RSS`, `sitemap`, `robotsTXT`, and `404` kinds, but these are only available during the rendering of each of these respective page's kind and therefore *not* available in any of the `Pages` collections.
|
||||
|
||||
`.Lang`
|
||||
: language taken from the language extension notation.
|
||||
|
||||
`.Language`
|
||||
: a language object that points to the language's definition in the site
|
||||
`config`.
|
||||
|
||||
`.Lastmod`
|
||||
: the date the content was last modified; `.Lastmod` pulls from the `lastmod` field in a content's front matter. If `lastmod` is not set, Hugo will default to the `date` field. See also `.ExpiryDate`, `.Date`, and `.PublishDate`.
|
||||
|
||||
`.LinkTitle`
|
||||
: access when creating links to the content. If set, Hugo will use the `linktitle` from the front matter before `title`.
|
||||
|
||||
`.Next`
|
||||
: pointer to the following content (based on the `publishdate` field in front matter).
|
||||
|
||||
`.NextInSection`
|
||||
: pointer to the following content within the same section (based on `publishdate` field in front matter).
|
||||
|
||||
`.OutputFormats`
|
||||
: contains all formats, including the current format, for a given page. Can be combined the with [`.Get` function](/functions/get/) to grab a specific format. (See [Output Formats](/templates/output-formats/).)
|
||||
|
||||
`.Pages`
|
||||
: a collection of associated pages. This value will be `nil` for regular content pages. `.Pages` is an alias for `.Data.Pages`.
|
||||
|
||||
`.Permalink`
|
||||
: the Permanent link for this page; see [Permalinks](/content-management/urls/)
|
||||
|
||||
`.Plain`
|
||||
: the Page content stripped of HTML tags and presented as a string.
|
||||
|
||||
`.PlainWords`
|
||||
: the Page content stripped of HTML as a `[]string` using Go's [`strings.Fields`](https://golang.org/pkg/strings/#Fields) to split `.Plain` into a slice.
|
||||
|
||||
`.Prev`
|
||||
: Pointer to the previous content (based on `publishdate` in front matter).
|
||||
|
||||
`.PrevInSection`
|
||||
: Pointer to the previous content within the same section (based on `publishdate` in front matter). For example, `{{if .PrevInSection}}{{.PrevInSection.Permalink}}{{end}}`.
|
||||
|
||||
`.PublishDate`
|
||||
: the date on which the content was or will be published; `.Publishdate` pulls from the `publishdate` field in a content's front matter. See also `.ExpiryDate`, `.Date`, and `.Lastmod`.
|
||||
|
||||
`.RSSLink`
|
||||
: link to the taxonomies' RSS link.
|
||||
|
||||
`.RawContent`
|
||||
: raw markdown content without the front matter. Useful with [remarkjs.com](
|
||||
http://remarkjs.com)
|
||||
|
||||
`.ReadingTime`
|
||||
: the estimated time, in minutes, it takes to read the content.
|
||||
|
||||
`.Ref`
|
||||
: returns the permalink for a given reference (e.g., `.Ref "sample.md"`). `.Ref` does *not* handle in-page fragments correctly. See [Cross References](/content-management/cross-references/).
|
||||
|
||||
`.RelPermalink`
|
||||
: the relative permanent link for this page.
|
||||
|
||||
`.RelRef`
|
||||
: returns the relative permalink for a given reference (e.g., `RelRef
|
||||
"sample.md"`). `.RelRef` does *not* handle in-page fragments correctly. See [Cross References](/content-management/cross-references/).
|
||||
|
||||
`.Section`
|
||||
: the [section](/content-management/sections/) this content belongs to.
|
||||
|
||||
`.Site`
|
||||
: see [Site Variables](/variables/site/).
|
||||
|
||||
`.Summary`
|
||||
: a generated summary of the content for easily showing a snippet in a summary view. The breakpoint can be set manually by inserting <code><!--more--></code> at the appropriate place in the content page. See [Content Summaries](/content-management/summaries/) for more details.
|
||||
|
||||
`.TableOfContents`
|
||||
: the rendered [table of contents](/content-management/toc/) for the page.
|
||||
|
||||
`.Title`
|
||||
: the title for this page.
|
||||
|
||||
`.Translations`
|
||||
: a list of translated versions of the current page. See [Multilingual Mode](/content-management/multilingual/) for more information.
|
||||
|
||||
`.Truncated`
|
||||
: a boolean, `true` if the `.Summary` is truncated. Useful for showing a "Read more..." link only when necessary. See [Summaries](/content-management/summaries/) for more information.
|
||||
|
||||
`.Type`
|
||||
: the [content type](/content-management/types/) of the content (e.g., `post`).
|
||||
|
||||
`.URL`
|
||||
: the URL for the page relative to the web root. Note that a `url` set directly in front matter overrides the default relative URL for the rendered page.
|
||||
|
||||
`.UniqueID`
|
||||
: the MD5-checksum of the content file's path.
|
||||
|
||||
`.Weight`
|
||||
: assigned weight (in the front matter) to this content, used in sorting.
|
||||
|
||||
`.WordCount`
|
||||
: the number of words in the content.
|
||||
|
||||
## Page-level Params
|
||||
|
||||
Any other value defined in the front matter in a content file, including taxonomies, will be made available as part of the `.Params` variable.
|
||||
|
||||
```
|
||||
---
|
||||
title: My First Post
|
||||
date: date: 2017-02-20T15:26:23-06:00
|
||||
categories: [one]
|
||||
tags: [two,three,four]
|
||||
```
|
||||
|
||||
With the above front matter, the `tags` and `categories` taxonomies are accessible via the following:
|
||||
|
||||
* `.Params.tags`
|
||||
* `.Params.categories`
|
||||
|
||||
{{% note "Casing of Params" %}}
|
||||
Page-level `.Params` are *only* accessible in lowercase.
|
||||
{{% /note %}}
|
||||
|
||||
The `.Params` variable is particularly useful for the introduction of user-defined front matter fields in content files. For example, a Hugo website on book reviews could have the following front matter in `/content/review/book01.md`:
|
||||
|
||||
```
|
||||
---
|
||||
...
|
||||
affiliatelink: "http://www.my-book-link.here"
|
||||
recommendedby: "My Mother"
|
||||
...
|
||||
---
|
||||
```
|
||||
|
||||
These fields would then be accessible to the `/themes/yourtheme/layouts/review/single.html` template through `.Params.affiliatelink` and `.Params.recommendedby`, respectively.
|
||||
|
||||
Two common situations where this type of front matter field could be introduced is as a value of a certain attribute like `href=""` or by itself to be displayed as text to the website's visitors.
|
||||
|
||||
{{< code file="/themes/yourtheme/layouts/review/single.html" >}}
|
||||
<h3><a href={{ printf "%s" $.Params.affiliatelink }}>Buy this book</a></h3>
|
||||
<p>It was recommended by {{ .Params.recommendedby }}.</p>
|
||||
{{< /code >}}
|
||||
|
||||
This template would render as follows, assuming you've set [`uglyURLs`](/content-management/urls/) to `false` in your [site `config`](/getting-started/configuration/):
|
||||
|
||||
{{< output file="yourbaseurl/review/book01/index.html" >}}
|
||||
<h3><a href="http://www.my-book-link.here">Buy this book</a></h3>
|
||||
<p>It was recommended by my Mother.</p>
|
||||
{{< /output >}}
|
||||
|
||||
{{% note %}}
|
||||
See [Archetypes](/content-management/archetypes/) for consistency of `Params` across pieces of content.
|
||||
{{% /note %}}
|
||||
|
||||
### The `.Param` Method
|
||||
|
||||
In Hugo, you can declare params in individual pages and globally for your entire website. A common use case is to have a general value for the site param and a more specific value for some of the pages (i.e., a header image):
|
||||
|
||||
```
|
||||
{{ $.Param "header_image" }}
|
||||
```
|
||||
|
||||
The `.Param` method provides a way to resolve a single value according to it's definition in a page parameter (i.e. in the content's front matter) or a site parameter (i.e., in your `config`).
|
||||
|
||||
### Access Nested Fields in Front Matter
|
||||
|
||||
When front matter contains nested fields like the following:
|
||||
|
||||
```
|
||||
---
|
||||
author:
|
||||
given_name: John
|
||||
family_name: Feminella
|
||||
display_name: John Feminella
|
||||
---
|
||||
```
|
||||
`.Param` can access these fields by concatenating the field names together with a dot:
|
||||
|
||||
```
|
||||
{{ $.Param "author.display_name" }}
|
||||
```
|
||||
|
||||
If your front matter contains a top-level key that is ambiguous with a nested key, as in the following case:
|
||||
|
||||
```
|
||||
---
|
||||
favorites.flavor: vanilla
|
||||
favorites:
|
||||
flavor: chocolate
|
||||
---
|
||||
```
|
||||
|
||||
The top-level key will be preferred. Therefore, the following method, when applied to the previous example, will print `vanilla` and not `chocolate`:
|
||||
|
||||
```
|
||||
{{ $.Param "favorites.flavor" }}
|
||||
=> vanilla
|
||||
```
|
36
docs/content/variables/shortcodes.md
Normal file
36
docs/content/variables/shortcodes.md
Normal file
|
@ -0,0 +1,36 @@
|
|||
---
|
||||
title: Shortcode Variables
|
||||
linktitle: Shortcode Variables
|
||||
description: Shortcodes can access page variables and also have their own specific built-in variables.
|
||||
date: 2017-03-12
|
||||
publishdate: 2017-03-12
|
||||
lastmod: 2017-03-12
|
||||
categories: [variables and params]
|
||||
#tags: [shortcodes]
|
||||
draft: false
|
||||
menu:
|
||||
docs:
|
||||
parent: "variables"
|
||||
weight: 20
|
||||
weight: 20
|
||||
sections_weight: 20
|
||||
aliases: []
|
||||
toc: false
|
||||
---
|
||||
|
||||
[Shortcodes][shortcodes] have access to parameters delimited in the shortcode declaration via [`.Get`][getfunction], page- and site-level variables, and also the following shortcode-specific fields:
|
||||
|
||||
`.Parent`
|
||||
: provides access to the parent shortcode context in nested shortcodes. This can be very useful for inheritance of common shortcode parameters from the root.
|
||||
|
||||
`.IsNamedParams`
|
||||
: boolean that returns `true` when the shortcode in question uses [named rather than positional parameters][shortcodes]
|
||||
|
||||
`.Inner`
|
||||
: represents the content between the opening and closing shortcode tags when a [closing shortcode][markdownshortcode] is used
|
||||
|
||||
[getfunction]: /functions/get/
|
||||
[markdownshortcode]: /content-management/shortcodes/#shortcodes-with-markdown
|
||||
[shortcodes]: /templates/shortcode-templates/
|
||||
|
||||
|
125
docs/content/variables/site.md
Normal file
125
docs/content/variables/site.md
Normal file
|
@ -0,0 +1,125 @@
|
|||
---
|
||||
title: Site Variables
|
||||
linktitle: Site Variables
|
||||
description: Many, but not all, site-wide variables are defined in your site's configuration. However, Hugo provides a number of built-in variables for convenient access to global values in your templates.
|
||||
date: 2017-02-01
|
||||
publishdate: 2017-02-01
|
||||
lastmod: 2017-02-01
|
||||
categories: [variables and params]
|
||||
#tags: [global,site]
|
||||
draft: false
|
||||
menu:
|
||||
docs:
|
||||
parent: "variables"
|
||||
weight: 10
|
||||
weight: 10
|
||||
sections_weight: 10
|
||||
aliases: [/variables/site-variables/]
|
||||
toc: true
|
||||
---
|
||||
|
||||
The following is a list of site-level (aka "global") variables. Many of these variables are defined in your site's [configuration file][config], whereas others are built into Hugo's core for convenient usage in your templates.
|
||||
|
||||
## Site Variables List
|
||||
|
||||
`.Site.AllPages`
|
||||
: array of all pages, regardless of their translation.
|
||||
|
||||
`.Site.Author`
|
||||
: a map of the authors as defined in the site configuration.
|
||||
|
||||
`.Site.BaseURL`
|
||||
: the base URL for the site as defined in the site configuration.
|
||||
|
||||
`.Site.BuildDrafts`
|
||||
: a boolean (default: `false`) to indicate whether to build drafts as defined in the site configuration.
|
||||
|
||||
`.Site.Copyright`
|
||||
: a string representing the copyright of your website as defined in the site configuration.
|
||||
|
||||
`.Site.Data`
|
||||
: custom data, see [Data Templates](/templates/data-templates/).
|
||||
|
||||
`.Site.DisqusShortname`
|
||||
: a string representing the shortname of the Disqus shortcode as defined in the site configuration.
|
||||
|
||||
`.Site.Files`
|
||||
: all source files for the Hugo website.
|
||||
|
||||
`.Site.GoogleAnalytics`
|
||||
: a string representing your tracking code for Google Analytics as defined in the site configuration.
|
||||
|
||||
`.Site.IsMultiLingual`
|
||||
: whether there are more than one language in this site. See [Multilingual](/content-management/multilingual/) for more information.
|
||||
|
||||
`.Site.Language.Lang`
|
||||
: the language code of the current locale (e.g., `en`).
|
||||
|
||||
`.Site.Language.LanguageName`
|
||||
: the full language name (e.g. `English`).
|
||||
|
||||
`.Site.Language.Weight`
|
||||
: the weight that defines the order in the `.Site.Languages` list.
|
||||
|
||||
`.Site.Language`
|
||||
: indicates the language currently being used to render the website. This object's attributes are set in site configurations' language definition.
|
||||
|
||||
`.Site.LanguageCode`
|
||||
: a string representing the language as defined in the site configuration. This is mostly used to populate the RSS feeds with the right language code.
|
||||
|
||||
`.Site.LanguagePrefix`
|
||||
: this can be used to prefix URLs to point to the correct language. It will even work when only one defined language. See also the functions [absLangURL](/functions/abslangurl/) and [relLangURL](/functions/rellangurl).
|
||||
|
||||
`.Site.Languages`
|
||||
: an ordered list (ordered by defined weight) of languages.
|
||||
|
||||
`.Site.LastChange`
|
||||
: a string representing the date/time of the most recent change to your site. This string is based on the [`date` variable in the front matter](/content-management/front-matter) of your content pages.
|
||||
|
||||
`.Site.Menus`
|
||||
: all of the menus in the site.
|
||||
|
||||
`.Site.Pages`
|
||||
: array of all content ordered by Date with the newest first. This array contains only the pages in the current language.
|
||||
|
||||
`.Site.Permalinks`
|
||||
: a string to override the default [permalink](/content-management/urls/) format as defined in the site configuration.
|
||||
|
||||
`.Site.RegularPages`
|
||||
: a shortcut to the *regular* page collection. `.Site.RegularPages` is equivalent to `where .Site.Pages "Kind" "page"`.
|
||||
|
||||
`.Site.RSSLink`
|
||||
: the URL for the site RSS.
|
||||
|
||||
`.Site.Sections`
|
||||
: top-level directories of the site.
|
||||
|
||||
`.Site.Taxonomies`
|
||||
: the [taxonomies](/taxonomies/usage/) for the entire site. Replaces the now-obsolete `.Site.Indexes` since v0.11. Also see section [Taxonomies elsewhere](#taxonomies-elsewhere).
|
||||
|
||||
`.Site.Title`
|
||||
: a string representing the title of the site.
|
||||
|
||||
## The `.Site.Params` Variable
|
||||
|
||||
`.Site.Params` is a container holding the values from the `params` section of your site configuration.
|
||||
|
||||
### Example: `.Site.Params`
|
||||
|
||||
The following `config.toml` defines a site-wide param for `description`:
|
||||
|
||||
```
|
||||
baseURL = "https://yoursite.example.com/"
|
||||
|
||||
[params]
|
||||
description = "Tesla's Awesome Hugo Site"
|
||||
author = "Nikola Tesla"
|
||||
```
|
||||
|
||||
You can use `.Site.Params` in a [partial template](/templates/partials/) to call the default site description:
|
||||
|
||||
{{< code file="layouts/partials/head.html" >}}
|
||||
<meta name="description" content="{{if .IsHome}}{{ $.Site.Params.description }}{{else}}{{.Description}}{{end}}" />
|
||||
{{< /code >}}
|
||||
|
||||
[config]: /getting-started/configuration/
|
32
docs/content/variables/sitemap.md
Normal file
32
docs/content/variables/sitemap.md
Normal file
|
@ -0,0 +1,32 @@
|
|||
---
|
||||
title: Sitemap Variables
|
||||
linktitle: Sitemap Variables
|
||||
description:
|
||||
date: 2017-03-12
|
||||
publishdate: 2017-03-12
|
||||
lastmod: 2017-03-12
|
||||
categories: [variables and params]
|
||||
#tags: [sitemap]
|
||||
draft: false
|
||||
menu:
|
||||
docs:
|
||||
parent: "variables"
|
||||
weight: 80
|
||||
weight: 80
|
||||
sections_weight: 80
|
||||
aliases: []
|
||||
toc: false
|
||||
---
|
||||
|
||||
A sitemap is a `Page` and therefore has all the [page variables][pagevars] available to use sitemap templates. They also have the following sitemap-specific variables available to them:
|
||||
|
||||
`.Sitemap.ChangeFreq`
|
||||
: the page change frequency
|
||||
|
||||
`.Sitemap.Priority`
|
||||
: the priority of the page
|
||||
|
||||
`.Sitemap.Filename`
|
||||
: the sitemap filename
|
||||
|
||||
[pagevars]: /variables/page/
|
84
docs/content/variables/taxonomy.md
Normal file
84
docs/content/variables/taxonomy.md
Normal file
|
@ -0,0 +1,84 @@
|
|||
---
|
||||
title: Taxonomy Variables
|
||||
linktitle:
|
||||
description: Taxonomy pages are of type `Page` and have all page-, site-, and list-level variables available to them. However, taxonomy terms templates have additional variables available to their templates.
|
||||
date: 2017-02-01
|
||||
publishdate: 2017-02-01
|
||||
lastmod: 2017-02-01
|
||||
categories: [variables and params]
|
||||
#tags: [taxonomies,terms]
|
||||
draft: false
|
||||
menu:
|
||||
docs:
|
||||
parent: "variables"
|
||||
weight: 30
|
||||
weight: 30
|
||||
sections_weight: 30
|
||||
aliases: []
|
||||
toc: true
|
||||
---
|
||||
|
||||
## Taxonomy Terms Page Variables
|
||||
|
||||
[Taxonomy terms pages][taxonomytemplates] are of the type `Page` and have the following additional variables.
|
||||
|
||||
For example, the following fields would be available in `layouts/_defaults/terms.html`, depending on how you organize your [taxonomy templates][taxonomytemplates]:
|
||||
|
||||
`.Data.Singular`
|
||||
: The singular name of the taxonomy (e.g., `tags => `tag`)
|
||||
|
||||
`.Data.Plural`
|
||||
: The plural name of the taxonomy (e.g., `tags => tags`)
|
||||
|
||||
`.Data.Pages`
|
||||
: The list of pages in the taxonomy
|
||||
|
||||
`.Data.Terms`
|
||||
: The taxonomy itself
|
||||
|
||||
`.Data.Terms.Alphabetical`
|
||||
: The taxonomy terms alphabetized
|
||||
|
||||
`.Data.Terms.ByCount`
|
||||
: The Terms ordered by popularity
|
||||
|
||||
Note that `.Data.Terms.Alphabetical` and `.Data.Terms.ByCount` can also be reversed:
|
||||
|
||||
* `.Data.Terms.Alphabetical.Reverse`
|
||||
* `.Data.Terms.ByCount.Reverse`
|
||||
|
||||
## Use `.Site.Taxonomies` Outside of Taxonomy Templates
|
||||
|
||||
The `.Site.Taxonomies` variable holds all the taxonomies defined site-wide. `.Site.Taxonomies` is a map of the taxonomy name to a list of its values (e.g., `"tags" -> ["tag1", "tag2", "tag3"]``). Each value, though, is not a string but rather a *Taxonomy variable*.
|
||||
|
||||
## The `.Taxonomy` Variable
|
||||
|
||||
The `.Taxonomy` variable, available, for example, as `.Site.Taxonomies.tags`, contains the list of tags (values) and, for each tag, their corresponding content pages.
|
||||
|
||||
### Example Usage of `.Site.Taxonomies`
|
||||
|
||||
The following [partial template][partials] will list all your site's taxonomies, each of their keys, and all the content assigned to each of the keys. For more examples of how to order and render your taxonomies, see [Taxonomy Templates][taxonomytemplates].
|
||||
|
||||
{{< code file="all-taxonomies-keys-and-pages.html" download="all-taxonomies-keys-and-pages.html" >}}
|
||||
<section>
|
||||
<ul>
|
||||
{{ range $taxonomyname, $taxonomy := .Site.Taxonomies }}
|
||||
<li><a href="{{ "/" | relLangURL}}{{ $taxonomyname | urlize }}">{{ $taxonomyname }}</a>
|
||||
<ul>
|
||||
{{ range $key, $value := $taxonomy }}
|
||||
<li> {{ $key }} </li>
|
||||
<ul>
|
||||
{{ range $value.Pages }}
|
||||
<li><a href="{{ .Permalink}}"> {{ .LinkTitle }} </a> </li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</section>
|
||||
{{< /code >}}
|
||||
|
||||
[partials]: /templates/partials/
|
||||
[taxonomytemplates]: /templates/taxonomy-templates/
|
Loading…
Add table
Add a link
Reference in a new issue