mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-20 21:31:32 +02:00
Merge commit 'eb16165694f868d73e57b6aed5c26ba5e98229de'
This commit is contained in:
@@ -22,20 +22,25 @@ aliases: []
|
||||
`dict` is especially useful for passing more than one value to a partial template.
|
||||
|
||||
|
||||
## Example: `dict` with Embedded SVGs
|
||||
## Example: Using `dict` to pass multiple values to a `partial`
|
||||
|
||||
The partial below creates a SVG and expects `fill` `height` and `width` from the caller:
|
||||
The partial below creates a SVG and expects `fill`, `height` and `width` from the caller:
|
||||
|
||||
**Partial definition**
|
||||
|
||||
{{< code file="layouts/partials/svgs/external-links.svg" download="external-links.svg" >}}
|
||||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" fill="{{ .fill }}" width="{{ .size }}" height="{{ .size }}" viewBox="0 0 32 32" aria-label="External Link">
|
||||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
fill="{{ .fill }}" width="{{ .width }}" height="{{ .height }}" viewBox="0 0 32 32" aria-label="External Link">
|
||||
<path d="M25.152 16.576v5.696q0 2.144-1.504 3.648t-3.648 1.504h-14.848q-2.144 0-3.648-1.504t-1.504-3.648v-14.848q0-2.112 1.504-3.616t3.648-1.536h12.576q0.224 0 0.384 0.16t0.16 0.416v1.152q0 0.256-0.16 0.416t-0.384 0.16h-12.576q-1.184 0-2.016 0.832t-0.864 2.016v14.848q0 1.184 0.864 2.016t2.016 0.864h14.848q1.184 0 2.016-0.864t0.832-2.016v-5.696q0-0.256 0.16-0.416t0.416-0.16h1.152q0.256 0 0.416 0.16t0.16 0.416zM32 1.152v9.12q0 0.48-0.352 0.8t-0.8 0.352-0.8-0.352l-3.136-3.136-11.648 11.648q-0.16 0.192-0.416 0.192t-0.384-0.192l-2.048-2.048q-0.192-0.16-0.192-0.384t0.192-0.416l11.648-11.648-3.136-3.136q-0.352-0.352-0.352-0.8t0.352-0.8 0.8-0.352h9.12q0.48 0 0.8 0.352t0.352 0.8z"></path>
|
||||
</svg>
|
||||
{{< /code >}}
|
||||
|
||||
These values can be stored in one object with `dict` and passed to the partial:
|
||||
**Partial call**
|
||||
|
||||
The `fill`, `height` and `width` values can be stored in one object with `dict` and passed to the partial:
|
||||
|
||||
{{< code file="layouts/_default/list.html" >}}
|
||||
{{ partial "svg/link-ext.svg" (dict "fill" "#01589B" "size" 10 "width" 20 ) }}
|
||||
{{ partial "svgs/external-links.svg" (dict "fill" "#01589B" "width" 10 "height" 20 ) }}
|
||||
{{< /code >}}
|
||||
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
---
|
||||
title: imageConfig
|
||||
linktitle: imageConfig
|
||||
description: Parses the image and returns the height, width, and color model.
|
||||
godocref:
|
||||
|
@@ -18,9 +18,10 @@ relatedfuncs: []
|
||||
deprecated: false
|
||||
aliases: []
|
||||
---
|
||||
|
||||
An useful example is to use it as `AND` filters when combined with where:
|
||||
|
||||
## AND filter in where query
|
||||
|
||||
```
|
||||
{{ $pages := where .Site.RegularPages "Type" "not in" (slice "page" "about") }}
|
||||
{{ $pages := $pages | union (where .Site.RegularPages "Params.pinned" true) }}
|
||||
|
@@ -29,17 +29,13 @@ As an example:
|
||||
Will "fill in the gaps" in the current site with, from left to right, content from the French site, and lastly the English.
|
||||
|
||||
|
||||
A more practical example is to fill in the missing translations for the "minority languages" with content from the main language:
|
||||
|
||||
A more practical example is to fill in the missing translations from the other languages:
|
||||
|
||||
```bash
|
||||
{{ $pages := .Site.RegularPages }}
|
||||
{{ .Scratch.Set "pages" $pages }}
|
||||
{{ $mainSite := .Sites.First }}
|
||||
{{ if ne $mainSite .Site }}
|
||||
{{ .Scratch.Set "pages" ($pages | lang.Merge $mainSite.RegularPages) }}
|
||||
{{ end }}
|
||||
{{ $pages := .Scratch.Get "pages" }}
|
||||
{{ $pages := .Site.RegularPages }}
|
||||
{{ range .Site.Home.Translations }}
|
||||
{{ $pages = $pages | lang.Merge .Site.RegularPages }}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
|
@@ -19,7 +19,12 @@ deprecated: false
|
||||
aliases: []
|
||||
---
|
||||
|
||||
The `partialCached` template function can offer significant performance gains for complex templates that don't need to be re-rendered on every invocation. Here is the simplest usage:
|
||||
The `partialCached` template function can offer significant performance gains for complex templates that don't need to be re-rendered on every invocation.
|
||||
|
||||
|
||||
**Note:** Each Site (or language) has its own `partialCached` cache, so each site will execute a partial once.
|
||||
|
||||
Here is the simplest usage:
|
||||
|
||||
```
|
||||
{{ partialCached "footer.html" . }}
|
||||
|
31
docs/content/en/functions/path.Base.md
Normal file
31
docs/content/en/functions/path.Base.md
Normal file
@@ -0,0 +1,31 @@
|
||||
---
|
||||
title: path.Base
|
||||
description: Base returns the last element of a path.
|
||||
godocref:
|
||||
date: 2018-11-28
|
||||
publishdate: 2018-11-28
|
||||
lastmod: 2018-11-28
|
||||
categories: [functions]
|
||||
menu:
|
||||
docs:
|
||||
parent: "functions"
|
||||
keywords: [path, base]
|
||||
signature: ["path.Base PATH"]
|
||||
workson: []
|
||||
hugoversion: "0.40"
|
||||
relatedfuncs: [path.Dir, path.Ext, path.Split]
|
||||
deprecated: false
|
||||
---
|
||||
|
||||
`path.Base` returns the last element of `PATH`.
|
||||
|
||||
If `PATH` is empty, `.` is returned.
|
||||
|
||||
**Note:** On Windows, `PATH` is converted to slash (`/`) separators.
|
||||
|
||||
```
|
||||
{{ path.Base "a/news.html" }} → "news.html"
|
||||
{{ path.Base "news.html" }} → "news.html"
|
||||
{{ path.Base "a/b/c" }} → "c"
|
||||
{{ path.Base "/x/y/z/" }} → "z"
|
||||
```
|
32
docs/content/en/functions/path.Dir.md
Normal file
32
docs/content/en/functions/path.Dir.md
Normal file
@@ -0,0 +1,32 @@
|
||||
---
|
||||
title: path.Dir
|
||||
description: Dir returns all but the last element of a path.
|
||||
godocref:
|
||||
date: 2018-11-28
|
||||
publishdate: 2018-11-28
|
||||
lastmod: 2018-11-28
|
||||
categories: [functions]
|
||||
menu:
|
||||
docs:
|
||||
parent: "functions"
|
||||
keywords: [path, dir]
|
||||
signature: ["path.Dir PATH"]
|
||||
workson: []
|
||||
hugoversion: "0.40"
|
||||
relatedfuncs: [path.Base, path.Ext, path.Split]
|
||||
deprecated: false
|
||||
---
|
||||
|
||||
`path.Dir` returns all but the last element of `PATH`, typically `PATH`'s directory.
|
||||
|
||||
The returned path will never end in a slash.
|
||||
If `PATH` is empty, `.` is returned.
|
||||
|
||||
**Note:** On Windows, `PATH` is converted to slash (`/`) separators.
|
||||
|
||||
```
|
||||
{{ path.Dir "a/news.html" }} → "a"
|
||||
{{ path.Dir "news.html" }} → "."
|
||||
{{ path.Dir "a/b/c" }} → "a/b"
|
||||
{{ path.Dir "/x/y/z" }} → "/x/y"
|
||||
```
|
29
docs/content/en/functions/path.Ext.md
Normal file
29
docs/content/en/functions/path.Ext.md
Normal file
@@ -0,0 +1,29 @@
|
||||
---
|
||||
title: path.Ext
|
||||
description: Ext returns the file name extension of a path.
|
||||
godocref:
|
||||
date: 2018-11-28
|
||||
publishdate: 2018-11-28
|
||||
lastmod: 2018-11-28
|
||||
categories: [functions]
|
||||
menu:
|
||||
docs:
|
||||
parent: "functions"
|
||||
keywords: [path, ext, extension]
|
||||
signature: ["path.Ext PATH"]
|
||||
workson: []
|
||||
hugoversion: "0.40"
|
||||
relatedfuncs: [path.Base, path.Dir, path.Split]
|
||||
deprecated: false
|
||||
---
|
||||
|
||||
`path.Ext` returns the file name extension `PATH`.
|
||||
|
||||
The extension is the suffix beginning at the final dot in the final slash-separated element `PATH`;
|
||||
it is empty if there is no dot.
|
||||
|
||||
**Note:** On Windows, `PATH` is converted to slash (`/`) separators.
|
||||
|
||||
```
|
||||
{{ path.Ext "a/b/c/news.html" }} → ".html"
|
||||
```
|
29
docs/content/en/functions/path.Join.md
Normal file
29
docs/content/en/functions/path.Join.md
Normal file
@@ -0,0 +1,29 @@
|
||||
---
|
||||
title: path.Join
|
||||
description: Join path elements into a single path.
|
||||
godocref:
|
||||
date: 2018-11-28
|
||||
publishdate: 2018-11-28
|
||||
lastmod: 2018-11-28
|
||||
categories: [functions]
|
||||
menu:
|
||||
docs:
|
||||
parent: "functions"
|
||||
keywords: [path, join]
|
||||
signature: ["path.Join ELEMENT..."]
|
||||
workson: []
|
||||
hugoversion: "0.39"
|
||||
relatedfuncs: [path.Split]
|
||||
deprecated: false
|
||||
---
|
||||
|
||||
`path.Join` joins path elements into a single path, adding a separating slash if necessary.
|
||||
All empty strings are ignored.
|
||||
|
||||
**Note:** All path elements on Windows are converted to slash ('/') separators.
|
||||
|
||||
```
|
||||
{{ path.Join "partial" "news.html" }} → "partial/news.html"
|
||||
{{ path.Join "partial/" "news.html" }} → "partial/news.html"
|
||||
{{ path.Join "foo/baz" "bar" }} → "foo/baz/bar"
|
||||
```
|
31
docs/content/en/functions/path.Split.md
Normal file
31
docs/content/en/functions/path.Split.md
Normal file
@@ -0,0 +1,31 @@
|
||||
---
|
||||
title: path.Split
|
||||
description: Split path immediately following the final slash.
|
||||
godocref:
|
||||
date: 2018-11-28
|
||||
publishdate: 2018-11-28
|
||||
lastmod: 2018-11-28
|
||||
categories: [functions]
|
||||
menu:
|
||||
docs:
|
||||
parent: "functions"
|
||||
keywords: [path, split]
|
||||
signature: ["path.Split PATH"]
|
||||
workson: []
|
||||
hugoversion: "0.39"
|
||||
relatedfuncs: [path.Split]
|
||||
deprecated: false
|
||||
---
|
||||
|
||||
`path.Split` splits `PATH` immediately following the final slash, separating it into a directory and a base component.
|
||||
|
||||
The returned values have the property that `PATH` = `DIR`+`BASE`.
|
||||
If there is no slash in `PATH`, it returns an empty directory and the base is set to `PATH`.
|
||||
|
||||
**Note:** On Windows, `PATH` is converted to slash (`/`) separators.
|
||||
|
||||
```
|
||||
{{ path.Split "a/news.html" }} → "a/", "news.html"
|
||||
{{ path.Split "news.html" }} → "", "news.html"
|
||||
{{ path.Split "a/b/c" }} → "a/b/", "c"
|
||||
```
|
@@ -1,6 +1,5 @@
|
||||
---
|
||||
title: render
|
||||
# linktitle: Render
|
||||
title: .Render
|
||||
description: Takes a view to apply when rendering content.
|
||||
godocref:
|
||||
date: 2017-02-01
|
||||
@@ -11,7 +10,7 @@ menu:
|
||||
docs:
|
||||
parent: "functions"
|
||||
keywords: [views]
|
||||
signature: ["render LAYOUT"]
|
||||
signature: [".Render LAYOUT"]
|
||||
workson: []
|
||||
hugoversion:
|
||||
relatedfuncs: []
|
||||
|
37
docs/content/en/functions/templates.Exists.md
Normal file
37
docs/content/en/functions/templates.Exists.md
Normal file
@@ -0,0 +1,37 @@
|
||||
---
|
||||
title: templates.Exists
|
||||
linktitle: ""
|
||||
description: "Checks whether a template file exists under the given path relative to the `layouts` directory."
|
||||
godocref: ""
|
||||
date: 2018-11-01
|
||||
publishdate: 2018-11-01
|
||||
lastmod: 2018-11-01
|
||||
categories: [functions]
|
||||
tags: []
|
||||
menu:
|
||||
docs:
|
||||
parent: "functions"
|
||||
ns: ""
|
||||
keywords: ["templates", "template", "layouts"]
|
||||
signature: ["templates.Exists PATH"]
|
||||
workson: []
|
||||
hugoversion: "0.46"
|
||||
aliases: []
|
||||
relatedfuncs: []
|
||||
toc: false
|
||||
deprecated: false
|
||||
---
|
||||
|
||||
A template file is any file living below the `layouts` directories of either the project or any of its theme components incudling partials and shortcodes.
|
||||
|
||||
The function is particulary handy with dynamic path. The following example ensures the build will not break on a `.Type` missing its dedicated `header` partial.
|
||||
|
||||
```go-html-template
|
||||
{{ $partialPath := printf "headers/%s.html" .Type }}
|
||||
{{ if templates.Exists ( printf "partials/%s" $partialPath ) }}
|
||||
{{ partial $partialPath . }}
|
||||
{{ else }}
|
||||
{{ partial "headers/default.html" . }}
|
||||
{{ end }}
|
||||
|
||||
```
|
@@ -35,6 +35,7 @@ Given two arrays (or slices) A and B, this function will return a new array that
|
||||
<!-- returns an error because both arrays/slices have to be of the same type -->
|
||||
```
|
||||
|
||||
## OR filter in where query
|
||||
|
||||
This is also very useful to use as `OR` filters when combined with where:
|
||||
|
||||
|
Reference in New Issue
Block a user