Add space after and before action delimiters

This commit is contained in:
Joe Mooring
2023-03-27 13:46:23 -07:00
committed by Joe Mooring
parent ac333c7954
commit f11cabf375
42 changed files with 101 additions and 106 deletions
@@ -344,7 +344,7 @@ The function will read `.Count` from `.ReadingTime` and evaluate whether the num
{{< code-toggle file="i18n/en-US" >}}
[readingTime]
one = "One minute to read"
other = "{{.Count}} minutes to read"
other = "{{.Count }} minutes to read"
{{< /code-toggle >}}
Assuming `.ReadingTime.Count` in the context has value is 525600. The result will be:
+4 -4
View File
@@ -15,7 +15,7 @@ aliases: [/extras/toc/]
{{% note "TOC Heading Levels are Fixed" %}}
Previously, there was no out-of-the-box way to specify which heading levels you want the TOC to render. [See the related GitHub discussion (#1778)](https://github.com/gohugoio/hugo/issues/1778). As such, the resulting `<nav id="TableOfContents"><ul></ul></nav>` was going to start at `<h1>` when pulling from `{{.Content}}`.
Previously, there was no out-of-the-box way to specify which heading levels you want the TOC to render. [See the related GitHub discussion (#1778)](https://github.com/gohugoio/hugo/issues/1778). As such, the resulting `<nav id="TableOfContents"><ul></ul></nav>` was going to start at `<h1>` when pulling from `{{.Content }}`.
Hugo [v0.60.0](https://github.com/gohugoio/hugo/releases/tag/v0.60.0) made a switch to [Goldmark](https://github.com/yuin/goldmark/) as the default library for Markdown which has improved and configurable implementation of TOC. Take a look at [how to configure TOC](/getting-started/configuration-markup/#table-of-contents) for Goldmark renderer.
@@ -73,15 +73,15 @@ The following is a [partial template][partials] that adds slightly more logic fo
{{ if and (gt .WordCount 400 ) (.Params.toc) }}
<aside>
<header>
<h2>{{.Title}}</h2>
<h2>{{.Title }}</h2>
</header>
{{.TableOfContents}}
{{.TableOfContents }}
</aside>
{{ end }}
{{< /code >}}
{{% note %}}
With the preceding example, even pages with > 400 words *and* `toc` not set to `false` will not render a table of contents if there are no headings in the page for the `{{.TableOfContents}}` variable to pull from.
With the preceding example, even pages with > 400 words *and* `toc` not set to `false` will not render a table of contents if there are no headings in the page for the `{{.TableOfContents }}` variable to pull from.
{{% /note %}}
## Usage with AsciiDoc
+9 -9
View File
@@ -81,7 +81,7 @@ Here is a review of the front matter fields automatically generated for you usin
`relatedfuncs`
: other [templating functions] you feel are related to your new function to help fellow Hugo users.
`{{.Content}}`
`{{.Content }}`
: an extended description of the new function; examples are not only welcomed but encouraged.
In the body of your function, expand the short description used in the front matter. Include as many examples as possible, and leverage the Hugo docs [`code` shortcode](#add-code-blocks). If you are unable to add examples but would like to solicit help from the Hugo community, add `needsexample: true` to your front matter.
@@ -145,15 +145,15 @@ This example HTML code block tells Hugo users the following:
<main>
<article>
<header>
<h1>{{.Title}}</h1>
{{with .Params.subtitle}}
<h1>{{.Title }}</h1>
{{ with .Params.subtitle }}
<span>{{.}}</span>
</header>
<div>
{{.Content}}
{{.Content }}
</div>
<aside>
{{.TableOfContents}}
{{.TableOfContents }}
</aside>
</article>
</main>
@@ -170,15 +170,15 @@ The output of this example will render to the Hugo docs as follows:
<main>
<article>
<header>
<h1>{{.Title}}</h1>
{{with .Params.subtitle}}
<h1>{{.Title }}</h1>
{{ with .Params.subtitle }}
<span>{{.}}</span>
</header>
<div>
{{.Content}}
{{.Content }}
</div>
<aside>
{{.TableOfContents}}
{{.TableOfContents }}
</aside>
</article>
</main>
+2 -2
View File
@@ -26,8 +26,8 @@ Some examples:
{{ $optBlock := dict "display" "block" }}
{{ $optOrg := dict "markup" "org" }}
{{ "**Bold Markdown**" | $p.RenderString }}
{{ "**Bold Block Markdown**" | $p.RenderString $optBlock }}
{{ "/italic org mode/" | $p.RenderString $optOrg }}
{{ "**Bold Block Markdown**" | $p.RenderString $optBlock }}
{{ "/italic org mode/" | $p.RenderString $optOrg }}
```
{{< new-in "0.93.0" >}} **Note**: [markdownify](/functions/markdownify/) uses this function in order to support [Render Hooks](/getting-started/configuration-markup/#markdown-render-hooks).
+4 -4
View File
@@ -40,9 +40,9 @@ You can use `after` in combination with the [`first` function] and Hugo's [power
<h2>Featured Article</h2>
{{ range first 1 .Pages.ByPublishDate.Reverse }}
<header>
<h3><a href="{{.Permalink}}">{{.Title}}</a></h3>
<h3><a href="{{.Permalink }}">{{.Title }}</a></h3>
</header>
<p>{{.Description}}</p>
<p>{{.Description }}</p>
{{ end }}
</section>
<div class="row recent-articles">
@@ -50,9 +50,9 @@ You can use `after` in combination with the [`first` function] and Hugo's [power
{{ range first 3 (after 1 .Pages.ByPublishDate.Reverse) }}
<section class="recent-article">
<header>
<h3><a href="{{.Permalink}}">{{.Title}}</a></h3>
<h3><a href="{{.Permalink }}">{{.Title }}</a></h3>
</header>
<p>{{.Description}}</p>
<p>{{.Description }}</p>
</section>
{{ end }}
</div>
+1 -1
View File
@@ -43,7 +43,7 @@ Using base64 to decode and encode becomes really powerful if we have to handle
responses from APIs.
```
{{ $resp := getJSON "https://api.github.com/repos/gohugoio/hugo/readme" }}
{{ $resp := getJSON "https://api.github.com/repos/gohugoio/hugo/readme" }}
{{ $resp.content | base64Decode | markdownify }}
```
+1 -1
View File
@@ -22,5 +22,5 @@ deprecated: false
Useful in a pipeline to remove newlines added by other processing (e.g., [`markdownify`](/functions/markdownify/)).
```
{{chomp "<p>Blockhead</p>\n"}} → "<p>Blockhead</p>"
{{ chomp "<p>Blockhead</p>\n"}} → "<p>Blockhead</p>"
```
+1 -1
View File
@@ -17,7 +17,7 @@ To find the elements within `$c3` that do not exist in `$c1` or `$c2`:
```go-html-template
{{ $c1 := slice 3 }}
{{ $c2 := slice 4 5 }}
{{ $c2 := slice 4 5 }}
{{ $c3 := slice 1 2 3 4 5 }}
{{ complement $c1 $c2 $c3 }} → [1 2]
+3 -3
View File
@@ -52,7 +52,7 @@ Both of the above `default` function calls return `Roboto`.
A `default` value, however, does not need to be hard coded like the previous example. The `default` value can be a variable or pulled directly from the front matter using dot notation:
{{< code file="variable-as-default-value.html" copy="false" >}}
{{$old := .Params.oldparam }}
{{ $old := .Params.oldparam }}
<p>{{ .Params.newparam | default $old }}</p>
{{< /code >}}
@@ -79,13 +79,13 @@ The following have equivalent return values but are far less terse. This demonst
Using `if`:
{{< code file="if-instead-of-default.html" copy="false" >}}
<title>{{if .Params.seo_title}}{{.Params.seo_title}}{{else}}{{.Title}}{{end}}</title>
<title>{{ if .Params.seo_title }}{{.Params.seo_title }}{{ else }}{{.Title }}{{ end }}</title>
=> Sane Defaults
{{< /code >}}
Using `with`:
{{< code file="with-instead-of-default.html" copy="false" >}}
<title>{{with .Params.seo_title}}{{.}}{{else}}{{.Title}}{{end}}</title>
<title>{{ with .Params.seo_title }}{{.}}{{ else }}{{.Title }}{{ end }}</title>
=> Sane Defaults
{{< /code >}}
+1 -1
View File
@@ -22,7 +22,7 @@ aliases: []
`delimit` called in your template takes the form of
```
{{ delimit array/slice/map delimiter optionallastdelimiter}}
{{ delimit array/slice/map delimiter optionallastdelimiter }}
```
`delimit` loops through any array, slice, or map and returns a string of all the values separated by a delimiter, the second argument in the function call. There is an optional third parameter that lets you choose a different delimiter to go between the last two values in the loop.
+1 -1
View File
@@ -100,7 +100,7 @@ An example table listing the dependencies:
<td>{{ with $element.Owner }}{{.Path }}{{ end }}</td>
<td>
{{ $element.Path }}
{{ with $element.Replace}}
{{ with $element.Replace }}
=> {{ .Path }}
{{ end }}
</td>
+4 -4
View File
@@ -22,8 +22,8 @@ If the input is either an int64 value or the string representation of an integer
```
{{humanize "my-first-post"}} → "My first post"
{{humanize "myCamelPost"}} → "My camel post"
{{humanize "52"}} → "52nd"
{{humanize 103}} → "103rd"
{{ humanize "my-first-post"}} → "My first post"
{{ humanize "myCamelPost"}} → "My camel post"
{{ humanize "52"}} → "52nd"
{{ humanize 103 }} → "103rd"
```
+1 -1
View File
@@ -222,6 +222,6 @@ images.ImageConfig PATH
```go-html-template
{{ with (imageConfig "favicon.ico") }}
favicon.ico: {{.Width}} x {{.Height}}
favicon.ico: {{.Width }} x {{.Height }}
{{ end }}
```
+1 -1
View File
@@ -25,6 +25,6 @@ Takes either a slice, array, or channel and an index or a map and a key as input
```
{{% warning %}}
All site-level configuration keys are stored as lower case. Therefore, a `myParam` key-value set in your [site configuration file](/getting-started/configuration/) needs to be accessed with `{{if isset .Site.Params "myparam"}}` and *not* with `{{if isset .Site.Params "myParam"}}`. Note that you can still access the same config key with `.Site.Params.myParam` *or* `.Site.Params.myparam`, for example, when using [`with`](/functions/with).
All site-level configuration keys are stored as lower case. Therefore, a `myParam` key-value set in your [site configuration file](/getting-started/configuration/) needs to be accessed with `{{ if isset .Site.Params "myparam"}}` and *not* with `{{ if isset .Site.Params "myParam"}}`. Note that you can still access the same config key with `.Site.Params.myParam` *or* `.Site.Params.myparam`, for example, when using [`with`](/functions/with).
This restriction also applies when accessing page-level front matter keys from within [shortcodes](/content-management/shortcodes/).
{{% /warning %}}
+1 -1
View File
@@ -39,7 +39,7 @@ You may want to append a class to a heading according to the length of the strin
{{< code file="check-title-length.html" >}}
<header>
<h1{{if gt (len .Title) 80}} class="long-title"{{end}}>{{.Title}}</h1>
<h1{{ if gt (len .Title) 80 }} class="long-title"{{ end }}>{{.Title }}</h1>
</header>
{{< /code >}}
+2 -2
View File
@@ -23,5 +23,5 @@ aliases: []
For example, 1 and 4 creates a slice including elements 1 through 3.
The `end` index can be omitted; it defaults to the string's length.
* `{{slicestr "BatMan" 3}}` → "Man"
* `{{slicestr "BatMan" 0 3}}` → "Bat"
* `{{ slicestr "BatMan" 3 }}` → "Man"
* `{{ slicestr "BatMan" 0 3 }}` → "Bat"
+1 -1
View File
@@ -18,4 +18,4 @@ deprecated: false
aliases: []
---
* `{{string "BatMan"}}` → "BatMan"
* `{{ string "BatMan"}}` → "BatMan"
+3 -3
View File
@@ -48,11 +48,11 @@ The following example takes a UNIX timestamp---set as `utimestamp: "1489276800"`
The following example may be useful when setting up [multilingual sites][multilingual]:
{{< code file="unix-to-month-integer.html" >}}
{{$time := time (int .Params.addDate)}}
{{ $time := time (int .Params.addDate)}}
=> $time = 1489276800
{{$time.Month}}
{{ $time.Month }}
=> "March"
{{$monthindex := printf "%d" $time.Month }}
{{ $monthindex := printf "%d" $time.Month }}
=> $monthindex = 3
{{< /code >}}
+1 -1
View File
@@ -22,7 +22,7 @@ aliases: []
```
{{title "BatMan"}}` → "Batman"
{{ title "BatMan"}}` → "Batman"
```
Can be combined in pipes. In the following snippet, the link text is cleaned up using `humanize` to remove dashes and `title` to convert the value of `$name` to Initial Caps.
+1 -1
View File
@@ -26,7 +26,7 @@ deprecated: false
`trim` *requires* the second argument, which tells the function specifically what to remove from the first argument. There is no default value for the second argument, so **the following usage will not work**:
```
{{ trim .Inner}}
{{ trim .Inner }}
```
Instead, the following example tells `trim` to remove extra new lines from the content contained in the [shortcode `.Inner` variable][shortcodevars]:
+4 -4
View File
@@ -31,18 +31,18 @@ The following might be used as a partial within a [single page template][singlet
{{< code file="layouts/partials/content-header.html" download="content-header.html" >}}
<header>
<h1>{{.Title}}</h1>
<h1>{{.Title }}</h1>
{{ with .Params.location }}
<div><a href="/locations/{{ . | urlize}}">{{.}}</a></div>
<div><a href="/locations/{{ . | urlize }}">{{.}}</a></div>
{{ end }}
<!-- Creates a list of tags for the content and links to each of their pages -->
{{ with .Params.tags }}
<ul>
{{range .}}
{{ range .}}
<li>
<a href="/tags/{{ . | urlize }}">{{ . }}</a>
</li>
{{end}}
{{ end }}
</ul>
{{ end }}
</header>
+1 -1
View File
@@ -17,7 +17,7 @@ The `urls.Parse` function parses a URL into a [URL structure](https://godoc.org/
```go-html-template
{{ $url := "https://example.org:123/foo?a=6&b=7#bar" }}
{{ $u := urls.Parse $url}}
{{ $u := urls.Parse $url }}
{{ $u.IsAbs }} → true
{{ $u.Scheme }} → https
+3 -3
View File
@@ -85,9 +85,9 @@ The following logical operators are available with `where`:
## Use `where` with `Booleans`
When using booleans you should not put quotation marks.
```go-html-template
{{range where .Pages "Draft" true}}
<p>{{.Title}}</p>
{{end}}
{{ range where .Pages "Draft" true }}
<p>{{.Title }}</p>
{{ end }}
```
+2 -2
View File
@@ -26,9 +26,9 @@ If you want to render a block if an index or key is present in a slice, array, c
The following example checks for a [user-defined site variable](/variables/site/) called `twitteruser`. If the key-value is not set, the following will render nothing:
{{< code file="layouts/partials/twitter.html" >}}
{{with .Site.Params.twitteruser}}<span class="twitter">
{{ with .Site.Params.twitteruser }}<span class="twitter">
<a href="https://twitter.com/{{.}}" rel="author">
<img src="/images/twitter.png" width="48" height="48" title="Twitter: {{.}}"
alt="Twitter"></a>
</span>{{end}}
</span>{{ end }}
{{< /code >}}
+2 -2
View File
@@ -108,13 +108,13 @@ Note that if you do not handle `.Err` yourself, Hugo will fail the build the fir
When fetching a remote `Resource`, `resources.GetRemote` takes an optional options map as the second argument, e.g.:
```go-html-template
{{ $resource := resources.GetRemote "https://example.org/api" (dict "headers" (dict "Authorization" "Bearer abcd")) }}
{{ $resource := resources.GetRemote "https://example.org/api" (dict "headers" (dict "Authorization" "Bearer abcd")) }}
```
If you need multiple values for the same header key, use a slice:
```go-html-template
{{ $resource := resources.GetRemote "https://example.org/api" (dict "headers" (dict "X-List" (slice "a" "b" "c"))) }}
{{ $resource := resources.GetRemote "https://example.org/api" (dict "headers" (dict "X-List" (slice "a" "b" "c"))) }}
```
You can also change the request method and set the request body:
+2 -7
View File
@@ -19,13 +19,13 @@ See [Image Processing Options](https://gohugo.io/content-management/image-proces
Another useful addon is the `$pages.Next` and `$pages.Prev` methods on the core page collections in Hugo. These works the same way as the built-in static variants one `Page`, e.g. `.Next` and `.NextInSection`:
```
{{with .Site.RegularPages.Next . }}{{.RelPermalink}}{{end}}
{{ with .Site.RegularPages.Next . }}{{.RelPermalink }}{{ end }}
```
The above is a functionally equivalent (but slightly slower) variant of:
```
{{with .Next }}{{.RelPermalink}}{{end}}
{{ with .Next }}{{.RelPermalink }}{{ end }}
```
See [Pages Methods](https://gohugo.io/variables/pages/) for more information.
@@ -113,8 +113,3 @@ Hugo now has:
* Fix cache key transformed resources [6dec671f](https://github.com/gohugoio/hugo/commit/6dec671fb930029e18ba9aa5135b3a27adcddb21) [@bep](https://github.com/bep) [#6348](https://github.com/gohugoio/hugo/issues/6348)
* Fix cache keys for bundled resoures in transform.Unmarshal [c0d75736](https://github.com/gohugoio/hugo/commit/c0d7573677e9726c14749ccd432dccb75e0d194d) [@bep](https://github.com/bep) [#6327](https://github.com/gohugoio/hugo/issues/6327)
* Fix concat with fingerprint regression [3be2c253](https://github.com/gohugoio/hugo/commit/3be2c25351b421a26ee1ff2a38cbab00280c0583) [@bep](https://github.com/bep) [#6309](https://github.com/gohugoio/hugo/issues/6309)
+1 -1
View File
@@ -87,7 +87,7 @@ The following shows how you can override both the `"main"` and `"title"` block a
{{< code file="layouts/_default/single.html" download="single.html" >}}
{{ define "title" }}
<!-- This will override the default value set in baseof.html; i.e., "{{.Site.Title}}" in the original example-->
<!-- This will override the default value set in baseof.html; i.e., "{{.Site.Title }}" in the original example-->
{{ .Title }} &ndash; {{ .Site.Title }}
{{ end }}
{{ define "main" }}
+4 -4
View File
@@ -131,7 +131,7 @@ Achievements:
You can use the following code to render the `Short Description` in your layout:
```go-html-template
<div>Short Description of {{.Site.Data.User0123.Name}}: <p>{{ index .Site.Data.User0123 "Short Description" | markdownify }}</p></div>
<div>Short Description of {{.Site.Data.User0123.Name }}: <p>{{ index .Site.Data.User0123 "Short Description" | markdownify }}</p></div>
```
Note the use of the [`markdownify` template function][markdownify]. This will send the description through the Markdown rendering engine.
@@ -173,13 +173,13 @@ This will resolve internally to the following:
Both `getJSON` and `getCSV` takes an optional map as the last argument, e.g.:
```go-html-template
{{ $data := getJSON "https://example.org/api" (dict "Authorization" "Bearer abcd") }}
{{ $data := getJSON "https://example.org/api" (dict "Authorization" "Bearer abcd") }}
```
If you need multiple values for the same header key, use a slice:
```go-html-template
{{ $data := getJSON "https://example.org/api" (dict "X-List" (slice "a" "b" "c")) }}
{{ $data := getJSON "https://example.org/api" (dict "X-List" (slice "a" "b" "c")) }}
```
### Example for CSV files
@@ -209,7 +209,7 @@ For `getCSV`, the one-character-long separator must be placed in the first posit
</table>
{{< /code >}}
The expression `{{index $r number}}` must be used to output the nth-column from the current row.
The expression `{{ index $r number }}` must be used to output the nth-column from the current row.
### Cache URLs
+3 -3
View File
@@ -38,20 +38,20 @@ See the homepage template below or [Content Organization][contentorg] for more i
## Example Homepage Template
The following is an example of a homepage template that uses [partial][partials], [base] templates, and a content file at `content/_index.md` to populate the `{{.Title}}` and `{{.Content}}` [page variables][pagevars].
The following is an example of a homepage template that uses [partial][partials], [base] templates, and a content file at `content/_index.md` to populate the `{{.Title }}` and `{{.Content }}` [page variables][pagevars].
{{< code file="layouts/index.html" download="index.html" >}}
{{ define "main" }}
<main aria-role="main">
<header class="homepage-header">
<h1>{{.Title}}</h1>
<h1>{{.Title }}</h1>
{{ with .Params.subtitle }}
<span class="subtitle">{{.}}</span>
{{ end }}
</header>
<div class="homepage-content">
<!-- Note that the content for index.html, as a sort of list page, will pull from content/_index.md -->
{{.Content}}
{{.Content }}
</div>
<div>
{{ range first 10 .Site.RegularPages }}
+7 -7
View File
@@ -241,7 +241,7 @@ If the _map_, _array_, or _slice_ passed into the range is zero-length then the
```go-html-template
{{ range $array }}
{{ . }}
{{else}}
{{ else }}
<!-- This is only evaluated if $array is empty -->
{{ end }}
```
@@ -414,7 +414,7 @@ The following shows how to define a variable independent of the context.
{{< /code >}}
{{% note %}}
Notice how once we have entered the loop (i.e. `range`), the value of `{{ . }}` has changed. We have defined a variable outside the loop (`{{$title}}`) that we've assigned a value so that we have access to the value from within the loop as well.
Notice how once we have entered the loop (i.e. `range`), the value of `{{ . }}` has changed. We have defined a variable outside the loop (`{{ $title }}`) that we've assigned a value so that we have access to the value from within the loop as well.
{{% /note %}}
### 2. Use `$.` to Access the Global Context
@@ -553,11 +553,11 @@ Here is an example of corresponding code that could be used inside a `toc.html`
{{ if not .Params.notoc }}
<aside>
<header>
<a href="#{{.Title | urlize}}">
<h3>{{.Title}}</h3>
<a href="#{{.Title | urlize }}">
<h3>{{.Title }}</h3>
</a>
</header>
{{.TableOfContents}}
{{.TableOfContents }}
</aside>
<a href="#" id="toc-toggle"></a>
{{ end }}
@@ -583,7 +583,7 @@ Within a footer layout, you might then declare a `<footer>` that is only rendere
```go-html-template
{{ if .Site.Params.copyrighthtml }}
<footer>
<div class="text-center">{{.Site.Params.CopyrightHTML | safeHTML}}</div>
<div class="text-center">{{.Site.Params.CopyrightHTML | safeHTML }}</div>
</footer>
{{ end }}
```
@@ -606,7 +606,7 @@ Finally, you can pull "magic constants" out of your layouts as well. The followi
<h1>Recent Posts</h1>
<ul>
{{- range first .Site.Params.SidebarRecentLimit .Site.Pages -}}
<li><a href="{{.RelPermalink}}">{{.Title}}</a></li>
<li><a href="{{.RelPermalink }}">{{.Title }}</a></li>
{{- end -}}
</ul>
</nav>
+8 -8
View File
@@ -94,16 +94,16 @@ You can now access this `_index.md`'s' content in your list template:
<main>
<article>
<header>
<h1>{{.Title}}</h1>
<h1>{{.Title }}</h1>
</header>
<!-- "{{.Content}}" pulls from the markdown content of the corresponding _index.md -->
{{.Content}}
<!-- "{{.Content }}" pulls from the markdown content of the corresponding _index.md -->
{{.Content }}
</article>
<ul>
<!-- Ranges through content/posts/*.md -->
{{ range .Pages }}
<li>
<a href="{{.Permalink}}">{{.Date.Format "2006-01-02"}} | {{.Title}}</a>
<a href="{{.Permalink }}">{{.Date.Format "2006-01-02"}} | {{.Title }}</a>
</li>
{{ end }}
</ul>
@@ -133,7 +133,7 @@ This above will output the following HTML:
### 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, the page will be created but with no `{{.Content}}` and only the default values for `.Title` etc.
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, 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 `quotes` section above will render the following output. Note that `quotes` does not have an `_index.md` file to pull from:
@@ -381,14 +381,14 @@ Hugo provides some functions for grouping pages by Section, Type, Date, etc.
{{ end }}
{{< /code >}}
In the above example, you may want `{{.Title}}` to point the `title` field you have added to your `_index.md` file instead. You can access this value using the [`.GetPage` function][getpage]:
In the above example, you may want `{{.Title }}` to point the `title` field you have added to your `_index.md` file instead. You can access this value using the [`.GetPage` function][getpage]:
{{< code file="layouts/partials/by-page-field.html" >}}
<!-- Groups content according to content section.-->
{{ range .Pages.GroupBy "Section" }}
<!-- Checks for existence of _index.md for a section; if available, pulls from "title" in front matter -->
{{ with $.Site.GetPage "section" .Key }}
<h3>{{.Title}}</h3>
<h3>{{.Title }}</h3>
{{ else }}
<!-- If no _index.md is available, ".Key" defaults to the section title and filters to title casing -->
<h3>{{ .Key | title }}</h3>
@@ -544,7 +544,7 @@ While these are logical defaults, they are not always the desired order. There a
### Order Within Groups
Because Grouping returns a `{{.Key}}` and a slice of pages, all the ordering methods listed above are available.
Because Grouping returns a `{{.Key }}` and a slice of pages, all the ordering methods listed above are available.
Here is the ordering for the example that follows:
+1 -1
View File
@@ -44,7 +44,7 @@ This partial template recursively "walks" a menu structure, rendering a localize
{{- define "partials/inline/menu/walk.html" }}
{{- $page := .page }}
{{- range .menuEntries }}
{{- $attrs := dict "href" .URL}}
{{- $attrs := dict "href" .URL }}
{{- if $page.IsMenuCurrent .Menu . }}
{{- $attrs = merge $attrs (dict "class" "active" "aria-current" "page") }}
{{- else if $page.HasMenuCurrent .Menu .}}
+1 -1
View File
@@ -59,7 +59,7 @@ The global page size setting (`Paginate`) can be overridden by providing a posit
It is also possible to use the `GroupBy` functions in combination with pagination:
```go-html-template
{{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }}
{{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }}
```
## Build the navigation
+2 -2
View File
@@ -108,7 +108,7 @@ Ordinal {{< new-in "0.108.0" >}}
Here is a code example for how the render-link.html template could look:
{{< code file="layouts/_default/_markup/render-link.html" >}}
<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if strings.HasPrefix .Destination "http" }} target="_blank" rel="noopener"{{ end }}>{{ .Text | safeHTML }}</a>
<a href="{{ .Destination | safeURL }}"{{ with .Title }} title="{{ . }}"{{ end }}{{ if strings.HasPrefix .Destination "http" }} target="_blank" rel="noopener"{{ end }}>{{ .Text | safeHTML }}</a>
{{< /code >}}
### Image Markdown example
@@ -121,7 +121,7 @@ Here is a code example for how the render-image.html template could look:
{{< code file="layouts/_default/_markup/render-image.html" >}}
<p class="md__image">
<img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" {{ with .Title}} title="{{ . }}"{{ end }} />
<img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" {{ with .Title }} title="{{ . }}"{{ end }} />
</p>
{{< /code >}}
+1 -1
View File
@@ -54,7 +54,7 @@ Examples:
{{ .Content }}
<ul class="contents">
{{ range .Paginator.Pages }}
<li>{{.Title}}
<li>{{.Title }}
<div>
{{ partial "summary.html" . }}
</div>
+2 -2
View File
@@ -321,9 +321,9 @@ You also have an `img` shortcode with a single named `src` parameter that you wa
{{< code file="layouts/shortcodes/img.html" >}}
{{- $src := .Get "src" -}}
{{- with .Parent -}}
<img src="{{$src}}" class="{{ .Get "class" }}-image">
<img src="{{ $src }}" class="{{ .Get "class" }}-image">
{{- else -}}
<img src="{{$src}}">
<img src="{{ $src }}">
{{- end -}}
{{< /code >}}
@@ -64,10 +64,10 @@ This single page template makes use of Hugo [base templates], the [`.Format` fun
</div>
<div>
{{ with .PrevInSection }}
<a class="previous" href="{{.Permalink}}"> {{.Title}}</a>
<a class="previous" href="{{.Permalink }}"> {{.Title }}</a>
{{ end }}
{{ with .NextInSection }}
<a class="next" href="{{.Permalink}}"> {{.Title}}</a>
<a class="next" href="{{.Permalink }}"> {{.Title }}</a>
{{ end }}
</div>
</aside>
+4 -4
View File
@@ -258,7 +258,7 @@ This would be very useful in a sidebar as “featured content”. You could even
<li>{{ $key }}</li>
<ul>
{{ range $taxonomy.Pages }}
<li hugo-nav="{{ .RelPermalink}}"><a href="{{ .Permalink}}">{{ .LinkTitle }}</a></li>
<li hugo-nav="{{ .RelPermalink }}"><a href="{{ .Permalink }}">{{ .LinkTitle }}</a></li>
{{ end }}
</ul>
{{ end }}
@@ -299,8 +299,8 @@ This example will list all taxonomies and their terms, as well as all the conten
<li>{{ $key }}</li>
<ul>
{{ range $value.Pages }}
<li hugo-nav="{{ .RelPermalink}}">
<a href="{{ .Permalink}}">{{ .LinkTitle }}</a>
<li hugo-nav="{{ .RelPermalink }}">
<a href="{{ .Permalink }}">{{ .LinkTitle }}</a>
</li>
{{ end }}
</ul>
@@ -322,7 +322,7 @@ Because taxonomies are lists, the [`.GetPage` function][getpage] can be used to
<ul class="{{ $taxo }}">
{{ with ($.Site.GetPage (printf "/%s" $taxo)) }}
{{ range .Pages }}
<li><a href="{{ .Permalink }}">{{ .Title}}</a></li>
<li><a href="{{ .Permalink }}">{{ .Title }}</a></li>
{{ end }}
{{ end }}
</ul>
+4 -4
View File
@@ -97,10 +97,10 @@ See also `.ExpiryDate`, `.Date`, `.PublishDate`, and [`.GitInfo`][gitinfo].
: access when creating links to the content. If set, Hugo will use the `linktitle` from the front matter before `title`.
.Next
: Points up to the next [regular page](/variables/site/#site-pages) (sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath)). Example: `{{with .Next}}{{.Permalink}}{{end}}`. Calling `.Next` from the first page returns `nil`.
: Points up to the next [regular page](/variables/site/#site-pages) (sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath)). Example: `{{ with .Next }}{{.Permalink }}{{ end }}`. Calling `.Next` from the first page returns `nil`.
.NextInSection
: Points up to the next [regular page](/variables/site/#site-pages) below the same top level section (e.g. in `/blog`)). Pages are sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath). Example: `{{with .NextInSection}}{{.Permalink}}{{end}}`. Calling `.NextInSection` from the first page returns `nil`.
: Points up to the next [regular page](/variables/site/#site-pages) below the same top level section (e.g. in `/blog`)). Pages are sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath). Example: `{{ with .NextInSection }}{{.Permalink }}{{ end }}`. Calling `.NextInSection` from the first page returns `nil`.
.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/).)
@@ -119,10 +119,10 @@ See also `.ExpiryDate`, `.Date`, `.PublishDate`, and [`.GitInfo`][gitinfo].
: the slice of strings that results from splitting .Plain into words, as defined in Go's [strings.Fields](https://pkg.go.dev/strings#Fields).
.Prev
: Points down to the previous [regular page](/variables/site/#site-pages) (sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath)). Example: `{{if .Prev}}{{.Prev.Permalink}}{{end}}`. Calling `.Prev` from the last page returns `nil`.
: Points down to the previous [regular page](/variables/site/#site-pages) (sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath)). Example: `{{ if .Prev }}{{.Prev.Permalink }}{{ end }}`. Calling `.Prev` from the last page returns `nil`.
.PrevInSection
: Points down to the previous [regular page](/variables/site/#site-pages) below the same top level section (e.g. `/blog`). Pages are sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath). Example: `{{if .PrevInSection}}{{.PrevInSection.Permalink}}{{end}}`. Calling `.PrevInSection` from the last page returns `nil`.
: Points down to the previous [regular page](/variables/site/#site-pages) below the same top level section (e.g. `/blog`). Pages are sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath). Example: `{{ if .PrevInSection }}{{.PrevInSection.Permalink }}{{ end }}`. Calling `.PrevInSection` from the last page returns `nil`.
.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`.
+2 -2
View File
@@ -23,8 +23,8 @@ Also see [List templates](/templates/lists) for an overview of sort methods.
`.Next` and `.Prev` on `Pages` work similar to the methods with the same names on `.Page`, but are more flexible (and slightly slower) as they can be used on any page collection.
`.Next` points **up** to the next page relative to the page sent in as the argument. Example: `{{with .Site.RegularPages.Next . }}{{.RelPermalink}}{{end}}`. Calling `.Next` with the first page in the collection returns `nil`.
`.Next` points **up** to the next page relative to the page sent in as the argument. Example: `{{ with .Site.RegularPages.Next . }}{{.RelPermalink }}{{ end }}`. Calling `.Next` with the first page in the collection returns `nil`.
## .Prev PAGE
`.Prev` points **down** to the previous page relative to the page sent in as the argument. Example: `{{with .Site.RegularPages.Prev . }}{{.RelPermalink}}{{end}}`. Calling `.Prev` with the last page in the collection returns `nil`.
`.Prev` points **down** to the previous page relative to the page sent in as the argument. Example: `{{ with .Site.RegularPages.Prev . }}{{.RelPermalink }}{{ end }}`. Calling `.Prev` with the last page in the collection returns `nil`.
+1 -1
View File
@@ -117,7 +117,7 @@ baseURL = "https://yoursite.example.com/"
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}}" />
<meta name="description" content="{{ if .IsHome }}{{ $.Site.Params.description }}{{ else }}{{.Description }}{{ end }}" />
{{< /code >}}
## The `.Site.Pages` Variable {#site-pages}
+1 -1
View File
@@ -124,7 +124,7 @@ For example, to render the entire taxonomy data structure as a nested unordered
<ul>
{{ range $weightedPages }}
<li>
<a href="{{ .RelPermalink}}"> {{ .LinkTitle }}</a>
<a href="{{ .RelPermalink }}"> {{ .LinkTitle }}</a>
</li>
{{ end }}
</ul>