<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Collections functions on Hugo</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/</link><description>Recent content in Collections functions on Hugo</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="https://v0-122-0--gohugoio.netlify.app/functions/collections/index.xml" rel="self" type="application/rss+xml"/><item><title>collections.After</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/after/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/after/</guid><description>The following shows after being used in conjunction with the slicefunction:
{{ $data := slice &amp;#34;one&amp;#34; &amp;#34;two&amp;#34; &amp;#34;three&amp;#34; &amp;#34;four&amp;#34; }} &amp;lt;ul&amp;gt; {{ range after 2 $data }} &amp;lt;li&amp;gt;{{ . }}&amp;lt;/li&amp;gt; {{ end }} &amp;lt;/ul&amp;gt; The template above is rendered to:
&amp;lt;ul&amp;gt; &amp;lt;li&amp;gt;three&amp;lt;/li&amp;gt; &amp;lt;li&amp;gt;four&amp;lt;/li&amp;gt; &amp;lt;/ul&amp;gt; Example of after with first: 2nd–4th most recent articles You can use after in combination with the first function and Hugo&amp;rsquo;s powerful sorting methods. Let&amp;rsquo;s assume you have a list page at example.</description></item><item><title>collections.Append</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/append/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/append/</guid><description>This function appends all elements, excluding the last, to the last element. This allows pipe constructs as shown below.
Append a single element to a slice:
{{ $s := slice &amp;#34;a&amp;#34; &amp;#34;b&amp;#34; }} {{ $s }} → [a b] {{ $s = $s | append &amp;#34;c&amp;#34; }} {{ $s }} → [a b c] Append two elements to a slice:
{{ $s := slice &amp;#34;a&amp;#34; &amp;#34;b&amp;#34; }} {{ $s }} → [a b] {{ $s = $s | append &amp;#34;c&amp;#34; &amp;#34;d&amp;#34; }} {{ $s }} → [a b c d] Append two elements, as a slice, to a slice.</description></item><item><title>collections.Apply</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/apply/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/apply/</guid><description>The apply function takes three or more arguments, depending on the function being applied to the collection elements.
The first argument is the collection itself, the second argument is the function name, and the remaining arguments are passed to the function, with the string &amp;quot;.&amp;quot; representing the collection element.
{{ $s := slice &amp;#34;hello&amp;#34; &amp;#34;world&amp;#34; }} {{ $s = apply $s &amp;#34;strings.FirstUpper&amp;#34; &amp;#34;.&amp;#34; }} {{ $s }} → [Hello World] {{ $s = apply $s &amp;#34;strings.</description></item><item><title>collections.Complement</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/complement/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/complement/</guid><description>To find the elements within $c3 that do not exist in $c1 or $c2:
{{ $c1 := slice 3 }} {{ $c2 := slice 4 5 }} {{ $c3 := slice 1 2 3 4 5 }} {{ complement $c1 $c2 $c3 }} → [1 2] Make your code simpler to understand by using a chained pipeline:
{{ $c3 | complement $c1 $c2 }} → [1 2] You can also use the complement function with page collections.</description></item><item><title>collections.Delimit</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/delimit/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/delimit/</guid><description>Delimit a slice:
{{ $s := slice &amp;#34;b&amp;#34; &amp;#34;a&amp;#34; &amp;#34;c&amp;#34; }} {{ delimit $s &amp;#34;, &amp;#34; }} → b, a, c {{ delimit $s &amp;#34;, &amp;#34; &amp;#34; and &amp;#34;}} → b, a and c Delimit a map:
The delimit function sorts maps by key, returning the values.
{{ $m := dict &amp;#34;b&amp;#34; 2 &amp;#34;a&amp;#34; 1 &amp;#34;c&amp;#34; 3 }} {{ delimit $m &amp;#34;, &amp;#34; }} → 1, 2, 3 {{ delimit $m &amp;#34;, &amp;#34; &amp;#34; and &amp;#34;}} → 1, 2 and 3</description></item><item><title>collections.Dictionary</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/dictionary/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/dictionary/</guid><description>{{ $m := dict &amp;#34;a&amp;#34; 1 &amp;#34;b&amp;#34; 2 }} The above produces this data structure:
{ &amp;#34;a&amp;#34;: 1, &amp;#34;b&amp;#34;: 2 } Note that the key can be either a string or a string slice. The latter is useful to create a deeply nested structure, e.g.:
{{ $m := dict (slice &amp;#34;a&amp;#34; &amp;#34;b&amp;#34; &amp;#34;c&amp;#34;) &amp;#34;value&amp;#34; }} The above produces this data structure:
{ &amp;#34;a&amp;#34;: { &amp;#34;b&amp;#34;: { &amp;#34;c&amp;#34;: &amp;#34;value&amp;#34; } } } Pass values to a partial template The partial below creates an SVG and expects fill, height and width from the caller:</description></item><item><title>collections.First</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/first/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/first/</guid><description>{{ range first 5 .Pages }} {{ .Render &amp;#34;summary&amp;#34; }} {{ end }} Set N to zero to return an empty collection.
{{ $emptyPageCollection := first 0 .Pages}} Use first and where together.
{{ range where .Pages &amp;#34;Section&amp;#34; &amp;#34;articles&amp;#34; | first 5 }} {{ .Render &amp;#34;summary&amp;#34; }} {{ end }}</description></item><item><title>collections.Group</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/group/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/group/</guid><description>{{ $new := .Site.RegularPages | first 10 | group &amp;#34;New&amp;#34; }} {{ $old := .Site.RegularPages | last 10 | group &amp;#34;Old&amp;#34; }} {{ $groups := slice $new $old }} {{ range $groups }} &amp;lt;h3&amp;gt;{{ .Key }}{{/* Prints &amp;#34;New&amp;#34;, &amp;#34;Old&amp;#34; */}}&amp;lt;/h3&amp;gt; &amp;lt;ul&amp;gt; {{ range .Pages }} &amp;lt;li&amp;gt; &amp;lt;a href=&amp;#34;{{ .RelPermalink }}&amp;#34;&amp;gt;{{ .LinkTitle }}&amp;lt;/a&amp;gt; &amp;lt;div class=&amp;#34;meta&amp;#34;&amp;gt;{{ .Date.Format &amp;#34;Mon, Jan 2, 2006&amp;#34; }}&amp;lt;/div&amp;gt; &amp;lt;/li&amp;gt; {{ end }} &amp;lt;/ul&amp;gt; {{ end }} The page group you get from group is of the same type you get from the built-in group methods in Hugo.</description></item><item><title>collections.In</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/in/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/in/</guid><description>The SET can be an array, slice, or string.
{{ $s := slice &amp;#34;a&amp;#34; &amp;#34;b&amp;#34; &amp;#34;c&amp;#34; }} {{ in $s &amp;#34;b&amp;#34; }} → true {{ $s := slice 1 2 3 }} {{ in $s 2 }} → true {{ $s := slice 1.11 2.22 3.33 }} {{ in $s 2.22 }} → true {{ $s := &amp;#34;abc&amp;#34; }} {{ in $s &amp;#34;b&amp;#34; }} → true</description></item><item><title>collections.Index</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/indexfunction/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/indexfunction/</guid><description>The index functions returns the result of indexing its first argument by the following arguments. Each indexed item must be a map or a slice, e.g.:
{{ $slice := slice &amp;#34;a&amp;#34; &amp;#34;b&amp;#34; &amp;#34;c&amp;#34; }} {{ index $slice 0 }} → a {{ index $slice 1 }} → b {{ $map := dict &amp;#34;a&amp;#34; 100 &amp;#34;b&amp;#34; 200 }} {{ index $map &amp;#34;b&amp;#34; }} → 200 The function takes multiple indices as arguments, and this can be used to get nested values, e.</description></item><item><title>collections.Intersect</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/intersect/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/intersect/</guid><description>A useful example is to use it as AND filters when combined with where:
{{ $pages := where .Site.RegularPages &amp;#34;Type&amp;#34; &amp;#34;not in&amp;#34; (slice &amp;#34;page&amp;#34; &amp;#34;about&amp;#34;) }} {{ $pages := $pages | union (where .Site.RegularPages &amp;#34;Params.pinned&amp;#34; true) }} {{ $pages := $pages | intersect (where .Site.RegularPages &amp;#34;Params.images&amp;#34; &amp;#34;!=&amp;#34; nil) }} The above fetches regular pages not of page or about type unless they are pinned. And finally, we exclude all pages with no images set in Page parameters.</description></item><item><title>collections.IsSet</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/isset/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/isset/</guid><description>For example, consider this site configuration:
hugo. yaml &amp;nbsp; toml &amp;nbsp; json &amp;nbsp; params: showHeroImage: false [params] showHeroImage = false { &amp;#34;params&amp;#34;: { &amp;#34;showHeroImage&amp;#34;: false } } It the value of showHeroImage is true, we can detect that it exists using either if or with:
{{ if site.Params.showHeroImage }} {{ site.Params.showHeroImage }} → true {{ end }} {{ with site.Params.showHeroImage }} {{ . }} → true {{ end }} But if the value of showHeroImage is false, we can&amp;rsquo;t use either if or with to detect its existence.</description></item><item><title>collections.KeyVals</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/keyvals/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/keyvals/</guid><description>The primary application for this function is the definition of the namedSlices parameter in the options map passed to the Related method on the Pages object.
See related content.
{{ $kv := keyVals &amp;#34;foo&amp;#34; &amp;#34;a&amp;#34; &amp;#34;b&amp;#34; &amp;#34;c&amp;#34; }} The resulting data structure is:
{ &amp;#34;Key&amp;#34;: &amp;#34;foo&amp;#34;, &amp;#34;Values&amp;#34;: [ &amp;#34;a&amp;#34;, &amp;#34;b&amp;#34;, &amp;#34;c&amp;#34; ] } To extract the key and values:
{{ $kv.Key }} → foo {{ $kv.Values }} → [a b c]</description></item><item><title>collections.Last</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/last/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/last/</guid><description>{{ range last 10 .Pages }} {{ .Render &amp;#34;summary&amp;#34; }} {{ end }} Set N to zero to return an empty collection.
{{ $emptyPageCollection := last 0 .Pages}} Use last and [where] together.
{{ range where .Pages &amp;#34;Section&amp;#34; &amp;#34;articles&amp;#34; | last 5 }} {{ .Render &amp;#34;summary&amp;#34; }} {{ end }}</description></item><item><title>collections.Merge</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/merge/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/merge/</guid><description>Returns the result of merging two or more maps from left to right. If a key already exists, merge updates its value. If a key is absent, merge inserts the value under the new key.
Key handling is case-insensitive.
The following examples use these map definitions:
{{ $m1 := dict &amp;#34;x&amp;#34; &amp;#34;foo&amp;#34; }} {{ $m2 := dict &amp;#34;x&amp;#34; &amp;#34;bar&amp;#34; &amp;#34;y&amp;#34; &amp;#34;wibble&amp;#34; }} {{ $m3 := dict &amp;#34;x&amp;#34; &amp;#34;baz&amp;#34; &amp;#34;y&amp;#34; &amp;#34;wobble&amp;#34; &amp;#34;z&amp;#34; (dict &amp;#34;a&amp;#34; &amp;#34;huey&amp;#34;) }} Example 1</description></item><item><title>collections.NewScratch</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/newscratch/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/newscratch/</guid><description>The collections.NewScratch function creates a locally scoped scratch pad to store and manipulate data. To create a scratch pad that is attached to a Page object, use the Scratch or Store method.
Methods Set Sets the value of a given key.
{{ $s := newScratch }} {{ $s.Set &amp;#34;greeting&amp;#34; &amp;#34;Hello&amp;#34; }} Get Gets the value of a given key.
{{ $s := newScratch }} {{ $s.Set &amp;#34;greeting&amp;#34; &amp;#34;Hello&amp;#34; }} {{ $s.</description></item><item><title>collections.Querify</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/querify/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/querify/</guid><description>querify takes a set or slice of key-value pairs and returns a query string that can be appended to a URL.
The following examples create a link to a search results page on Google.
&amp;lt;a href=&amp;#34;https://www.google.com?{{ (querify &amp;#34;q&amp;#34; &amp;#34;test&amp;#34; &amp;#34;page&amp;#34; 3) | safeURL }}&amp;#34;&amp;gt;Search&amp;lt;/a&amp;gt; {{ $qs := slice &amp;#34;q&amp;#34; &amp;#34;test&amp;#34; &amp;#34;page&amp;#34; 3 }} &amp;lt;a href=&amp;#34;https://www.google.com?{{ (querify $qs) | safeURL }}&amp;#34;&amp;gt;Search&amp;lt;/a&amp;gt; Both of these examples render the following HTML:
&amp;lt;a href=&amp;#34;https://www.google.com?page=3&amp;amp;q=test&amp;#34;&amp;gt;Search&amp;lt;/a&amp;gt;</description></item><item><title>collections.Reverse</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/reverse/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/reverse/</guid><description>{{ slice 2 1 3 | collections.Reverse }} → [3 1 2]</description></item><item><title>collections.Seq</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/seq/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/seq/</guid><description>{{ seq 2 }} → [1 2] {{ seq 0 2 }} → [0 1 2] {{ seq -2 2 }} → [-2 -1 0 1 2] {{ seq -2 2 2 }} → [-2 0 2] A contrived example of iterating over a sequence of integers:
{{ $product := 1 }} {{ range seq 4 }} {{ $product = mul $product . }} {{ end }} {{ $product }} → 24 The slice created by the seq function is limited to 2000 elements.</description></item><item><title>collections.Shuffle</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/shuffle/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/shuffle/</guid><description>{{ shuffle (seq 1 2 3) }} → [3 1 2] {{ shuffle (slice &amp;#34;a&amp;#34; &amp;#34;b&amp;#34; &amp;#34;c&amp;#34;) }} → [b a c] The result will vary from one build to the next.</description></item><item><title>collections.Slice</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/slice/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/slice/</guid><description>{{ $s := slice &amp;#34;a&amp;#34; &amp;#34;b&amp;#34; &amp;#34;c&amp;#34; }} {{ $s }} → [a b c]</description></item><item><title>collections.Sort</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/sort/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/sort/</guid><description>The KEY is optional when sorting slices in ascending order, otherwise it is required. When sorting slices, use the literal value in place of the KEY. See examples below.
The ORDER may be either asc (ascending) or desc (descending). The default sort order is ascending.
Sort a slice The examples below assume this site configuration:
hugo. yaml &amp;nbsp; toml &amp;nbsp; json &amp;nbsp; params: grades: - b - a - c [params] grades = [&amp;#39;b&amp;#39;, &amp;#39;a&amp;#39;, &amp;#39;c&amp;#39;] { &amp;#34;params&amp;#34;: { &amp;#34;grades&amp;#34;: [ &amp;#34;b&amp;#34;, &amp;#34;a&amp;#34;, &amp;#34;c&amp;#34; ] } } Ascending order Sort slice elements in ascending order using either of these constructs:</description></item><item><title>collections.SymDiff</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/symdiff/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/symdiff/</guid><description>Example:
{{ slice 1 2 3 | symdiff (slice 3 4) }} → [1 2 4] Also see https://en.wikipedia.org/wiki/Symmetric_difference.</description></item><item><title>collections.Union</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/union/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/union/</guid><description>Given two arrays (or slices) A and B, this function will return a new array that contains the elements or objects that belong to either A or to B or to both.
{{ union (slice 1 2 3) (slice 3 4 5) }} &amp;lt;!-- returns [1 2 3 4 5] --&amp;gt; {{ union (slice 1 2 3) nil }} &amp;lt;!-- returns [1 2 3] --&amp;gt; {{ union nil (slice 1 2 3) }} &amp;lt;!</description></item><item><title>collections.Uniq</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/uniq/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/uniq/</guid><description>{{ slice 1 3 2 1 | uniq }} → [1 3 2]</description></item><item><title>collections.Where</title><link>https://v0-122-0--gohugoio.netlify.app/functions/collections/where/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/collections/where/</guid><description>The where function returns the given collection, removing elements that do not satisfy the comparison condition. The comparison condition is comprised of the KEY, OPERATOR, and VALUE arguments:
collections.Where COLLECTION KEY [OPERATOR] VALUE -------------------- comparison condition Hugo will test for equality if you do not provide an OPERATOR argument. For example:
{{ $pages := where .Site.RegularPages &amp;#34;Section&amp;#34; &amp;#34;books&amp;#34; }} {{ $books := where .Site.Data.books &amp;#34;genres&amp;#34; &amp;#34;suspense&amp;#34; }} Arguments The where function takes three or four arguments.</description></item></channel></rss>