summaryrefslogtreecommitdiffstats
path: root/docs/content/en/functions
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-12-12 09:06:42 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-12-12 09:06:42 +0100
commitb17a61a6056a516949dd9aa11034c39c9ad8e37e (patch)
tree78003ee569b95f867f24174ff4fdff0672b732ef /docs/content/en/functions
parent7829474088f835251f04caa1121d47e35fe89f7e (diff)
parenteb16165694f868d73e57b6aed5c26ba5e98229de (diff)
Diffstat (limited to 'docs/content/en/functions')
-rw-r--r--docs/content/en/functions/dict.md15
-rw-r--r--docs/content/en/functions/imageConfig.md1
-rw-r--r--docs/content/en/functions/intersect.md3
-rw-r--r--docs/content/en/functions/lang.Merge.md14
-rw-r--r--docs/content/en/functions/partialCached.md7
-rw-r--r--docs/content/en/functions/path.Base.md31
-rw-r--r--docs/content/en/functions/path.Dir.md32
-rw-r--r--docs/content/en/functions/path.Ext.md29
-rw-r--r--docs/content/en/functions/path.Join.md29
-rw-r--r--docs/content/en/functions/path.Split.md31
-rw-r--r--docs/content/en/functions/render.md5
-rw-r--r--docs/content/en/functions/templates.Exists.md37
-rw-r--r--docs/content/en/functions/union.md1
13 files changed, 216 insertions, 19 deletions
diff --git a/docs/content/en/functions/dict.md b/docs/content/en/functions/dict.md
index 9887dbaf9..007cc30c5 100644
--- a/docs/content/en/functions/dict.md
+++ b/docs/content/en/functions/dict.md
@@ -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 >}}
diff --git a/docs/content/en/functions/imageConfig.md b/docs/content/en/functions/imageConfig.md
index 614d04711..3952448c6 100644
--- a/docs/content/en/functions/imageConfig.md
+++ b/docs/content/en/functions/imageConfig.md
@@ -1,4 +1,5 @@
---
+title: imageConfig
linktitle: imageConfig
description: Parses the image and returns the height, width, and color model.
godocref:
diff --git a/docs/content/en/functions/intersect.md b/docs/content/en/functions/intersect.md
index 53f26d950..9ab7f3c3a 100644
--- a/docs/content/en/functions/intersect.md
+++ b/docs/content/en/functions/intersect.md
@@ -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) }}
diff --git a/docs/content/en/functions/lang.Merge.md b/docs/content/en/functions/lang.Merge.md
index 6e1d41c0f..ecdab3c42 100644
--- a/docs/content/en/functions/lang.Merge.md
+++ b/docs/content/en/functions/lang.Merge.md
@@ -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 %}}
diff --git a/docs/content/en/functions/partialCached.md b/docs/content/en/functions/partialCached.md
index 515143d46..7becea24b 100644
--- a/docs/content/en/functions/partialCached.md
+++ b/docs/content/en/functions/partialCached.md
@@ -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" . }}
diff --git a/docs/content/en/functions/path.Base.md b/docs/content/en/functions/path.Base.md
new file mode 100644
index 000000000..87eb67355
--- /dev/null
+++ b/docs/content/en/functions/path.Base.md
@@ -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"
+```
diff --git a/docs/content/en/functions/path.Dir.md b/docs/content/en/functions/path.Dir.md
new file mode 100644
index 000000000..54a3fb8be
--- /dev/null
+++ b/docs/content/en/functions/path.Dir.md
@@ -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"
+```
diff --git a/docs/content/en/functions/path.Ext.md b/docs/content/en/functions/path.Ext.md
new file mode 100644
index 000000000..a36b006f3
--- /dev/null
+++ b/docs/content/en/functions/path.Ext.md
@@ -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"
+```
diff --git a/docs/content/en/functions/path.Join.md b/docs/content/en/functions/path.Join.md
new file mode 100644
index 000000000..06a8121f0
--- /dev/null
+++ b/docs/content/en/functions/path.Join.md
@@ -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"
+```
diff --git a/docs/content/en/functions/path.Split.md b/docs/content/en/functions/path.Split.md
new file mode 100644
index 000000000..d6bc15ce9
--- /dev/null
+++ b/docs/content/en/functions/path.Split.md
@@ -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"
+```
diff --git a/docs/content/en/functions/render.md b/docs/content/en/functions/render.md
index c76af39fe..e3909bde3 100644
--- a/docs/content/en/functions/render.md
+++ b/docs/content/en/functions/render.md
@@ -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: []
diff --git a/docs/content/en/functions/templates.Exists.md b/docs/content/en/functions/templates.Exists.md
new file mode 100644
index 000000000..919a9c3b7
--- /dev/null
+++ b/docs/content/en/functions/templates.Exists.md
@@ -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 }}
+
+``` \ No newline at end of file
diff --git a/docs/content/en/functions/union.md b/docs/content/en/functions/union.md
index 5c93e4bc7..db3c14283 100644
--- a/docs/content/en/functions/union.md
+++ b/docs/content/en/functions/union.md
@@ -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: