<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Go template functions, operators, and statements on Hugo</title><link>https://v0-122-0--gohugoio.netlify.app/functions/go-template/</link><description>Recent content in Go template functions, operators, and statements on Hugo</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="https://v0-122-0--gohugoio.netlify.app/functions/go-template/index.xml" rel="self" type="application/rss+xml"/><item><title>and</title><link>https://v0-122-0--gohugoio.netlify.app/functions/go-template/and/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/go-template/and/</guid><description>In Go templates, the falsy values are false, 0, any nil pointer or interface value, and any array, slice, map, or string of length zero. Everything else is truthy.
{{ and 1 0 &amp;#34;&amp;#34; }} → 0 (int) {{ and 1 false 0 }} → false (bool) {{ and 1 2 3 }} → 3 (int) {{ and &amp;#34;a&amp;#34; &amp;#34;b&amp;#34; &amp;#34;c&amp;#34; }} → c (string) {{ and &amp;#34;a&amp;#34; 1 true }} → true (bool) See Go&amp;rsquo;s text/template documentation for more information.</description></item><item><title>block</title><link>https://v0-122-0--gohugoio.netlify.app/functions/go-template/block/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/go-template/block/</guid><description>A block is shorthand for defining a template:
{{ define &amp;#34;name&amp;#34; }} T1 {{ end }} and then executing it in place:
{{ template &amp;#34;name&amp;#34; pipeline }} The typical use is to define a set of root templates that are then customized by redefining the block templates within.
layouts/_default/baseof.html &amp;lt;body&amp;gt; &amp;lt;main&amp;gt; {{ block &amp;#34;main&amp;#34; . }} {{ print &amp;#34;default value if &amp;#39;main&amp;#39; template is empty&amp;#34; }} {{ end }} &amp;lt;/main&amp;gt; &amp;lt;/body&amp;gt; layouts/_default/single.</description></item><item><title>break</title><link>https://v0-122-0--gohugoio.netlify.app/functions/go-template/break/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/go-template/break/</guid><description>This template code:
{{ $s := slice &amp;#34;foo&amp;#34; &amp;#34;bar&amp;#34; &amp;#34;baz&amp;#34; }} {{ range $s }} {{ if eq . &amp;#34;bar&amp;#34; }} {{ break }} {{ end }} &amp;lt;p&amp;gt;{{ . }}&amp;lt;/p&amp;gt; {{ end }} Is rendered to:
&amp;lt;p&amp;gt;foo&amp;lt;/p&amp;gt; See Go&amp;rsquo;s text/template documentation for more information.</description></item><item><title>continue</title><link>https://v0-122-0--gohugoio.netlify.app/functions/go-template/continue/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/go-template/continue/</guid><description>This template code:
{{ $s := slice &amp;#34;foo&amp;#34; &amp;#34;bar&amp;#34; &amp;#34;baz&amp;#34; }} {{ range $s }} {{ if eq . &amp;#34;bar&amp;#34; }} {{ continue }} {{ end }} &amp;lt;p&amp;gt;{{ . }}&amp;lt;/p&amp;gt; {{ end }} Is rendered to:
&amp;lt;p&amp;gt;foo&amp;lt;/p&amp;gt; &amp;lt;p&amp;gt;baz&amp;lt;/p&amp;gt; See Go&amp;rsquo;s text/template documentation for more information.</description></item><item><title>define</title><link>https://v0-122-0--gohugoio.netlify.app/functions/go-template/define/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/go-template/define/</guid><description>Use with the block statement:
{{ block &amp;#34;main&amp;#34; . }} {{ print &amp;#34;default value if &amp;#39;main&amp;#39; template is empty&amp;#34; }} {{ end }} {{ define &amp;#34;main&amp;#34; }} &amp;lt;h1&amp;gt;{{ .Title }}&amp;lt;/h1&amp;gt; {{ .Content }} {{ end }} Use with the partial function:
{{ partial &amp;#34;inline/foo.html&amp;#34; (dict &amp;#34;answer&amp;#34; 42) }} {{ define &amp;#34;partials/inline/foo.html&amp;#34; }} {{ printf &amp;#34;The answer is %v.&amp;#34; .answer }} {{ end }} Use with the template function:
{{ template &amp;#34;foo&amp;#34; (dict &amp;#34;answer&amp;#34; 42) }} {{ define &amp;#34;foo&amp;#34; }} {{ printf &amp;#34;The answer is %v.</description></item><item><title>else</title><link>https://v0-122-0--gohugoio.netlify.app/functions/go-template/else/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/go-template/else/</guid><description>Use with the if statement:
{{ $var := &amp;#34;foo&amp;#34; }} {{ if $var }} {{ $var }} → foo {{ else }} {{ print &amp;#34;var is falsy&amp;#34; }} {{ end }} Use with the with statement:
{{ $var := &amp;#34;foo&amp;#34; }} {{ with $var }} {{ . }} → foo {{ else }} {{ print &amp;#34;var is falsy&amp;#34; }} {{ end }} Use with the range statement:
{{ $var := slice 1 2 3 }} {{ range $var }} {{ .</description></item><item><title>end</title><link>https://v0-122-0--gohugoio.netlify.app/functions/go-template/end/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/go-template/end/</guid><description>Use with the if statement:
{{ $var := &amp;#34;foo&amp;#34; }} {{ if $var }} {{ $var }} → foo {{ end }} Use with the with statement:
{{ $var := &amp;#34;foo&amp;#34; }} {{ with $var }} {{ . }} → foo {{ end }} Use with the range statement:
{{ $var := slice 1 2 3 }} {{ range $var }} {{ . }} → 1 2 3 {{ end }} Use with the block statement:</description></item><item><title>if</title><link>https://v0-122-0--gohugoio.netlify.app/functions/go-template/if/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/go-template/if/</guid><description>In Go templates, the falsy values are false, 0, any nil pointer or interface value, and any array, slice, map, or string of length zero. Everything else is truthy.
{{ $var := &amp;#34;foo&amp;#34; }} {{ if $var }} {{ $var }} → foo {{ end }} Use with the else statement:
{{ $var := &amp;#34;foo&amp;#34; }} {{ if $var }} {{ $var }} → foo {{ else }} {{ print &amp;#34;var is falsy&amp;#34; }} {{ end }} Use else if to check multiple conditions.</description></item><item><title>len</title><link>https://v0-122-0--gohugoio.netlify.app/functions/go-template/len/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/go-template/len/</guid><description>With a string:
{{ &amp;#34;ab&amp;#34; | len }} → 2 {{ &amp;#34;&amp;#34; | len }} → 0 With a slice:
{{ slice &amp;#34;a&amp;#34; &amp;#34;b&amp;#34; | len }} → 2 {{ slice | len }} → 0 With a map:
{{ dict &amp;#34;a&amp;#34; 1 &amp;#34;b&amp;#34; 2 | len }} → 2 {{ dict | len }} → 0 With a collection:
{{ site.RegularPages | len }} → 42 You may also determine the number of pages in a collection with:</description></item><item><title>not</title><link>https://v0-122-0--gohugoio.netlify.app/functions/go-template/not/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/go-template/not/</guid><description>Unlike the and and or operators, the not operator always returns a boolean value.
{{ not true }} → false {{ not false }} → true {{ not 1 }} → false {{ not 0 }} → true {{ not &amp;#34;x&amp;#34; }} → false {{ not &amp;#34;&amp;#34; }} → true Use the not operator, twice in succession, to cast any value to a boolean value. For example:
{{ 42 | not | not }} → true {{ &amp;#34;&amp;#34; | not | not }} → false See Go&amp;rsquo;s text/template documentation for more information.</description></item><item><title>or</title><link>https://v0-122-0--gohugoio.netlify.app/functions/go-template/or/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/go-template/or/</guid><description>In Go templates, the falsy values are false, 0, any nil pointer or interface value, and any array, slice, map, or string of length zero. Everything else is truthy.
{{ or 0 1 2 }} → 1 {{ or false &amp;#34;a&amp;#34; 1 }} → a {{ or 0 true &amp;#34;a&amp;#34; }} → true {{ or false &amp;#34;&amp;#34; 0 }} → 0 {{ or 0 &amp;#34;&amp;#34; false }} → false See Go&amp;rsquo;s text/template documentation for more information.</description></item><item><title>range</title><link>https://v0-122-0--gohugoio.netlify.app/functions/go-template/range/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/go-template/range/</guid><description>In Go templates, the falsy values are false, 0, any nil pointer or interface value, and any array, slice, map, or string of length zero. Everything else is truthy.
{{ $s := slice &amp;#34;foo&amp;#34; &amp;#34;bar&amp;#34; &amp;#34;baz&amp;#34; }} {{ range $s }} {{ . }} → foo bar baz {{ end }} Use with the else statement:
{{ $s := slice &amp;#34;foo&amp;#34; &amp;#34;bar&amp;#34; &amp;#34;baz&amp;#34; }} {{ range $s }} &amp;lt;p&amp;gt;{{ . }}&amp;lt;/p&amp;gt; {{ else }} &amp;lt;p&amp;gt;The collection is empty&amp;lt;/p&amp;gt; {{ end }} Within a range block:</description></item><item><title>return</title><link>https://v0-122-0--gohugoio.netlify.app/functions/go-template/return/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/go-template/return/</guid><description>The return statement is a custom addition to Go&amp;rsquo;s text/template package. Used within partial templates, the return statement terminates template execution and returns the given value, if any.
The returned value may be of any data type including, but not limited to, bool, float, int, map, resource, slice, and string.
A return statement without a value returns an empty string of type template.HTML.
Unlike return statements in other languages, Hugo executes the first occurrence of the return statement regardless of its position within logical blocks.</description></item><item><title>template</title><link>https://v0-122-0--gohugoio.netlify.app/functions/go-template/template/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/go-template/template/</guid><description>Use the template function to execute internal templates. For example:
{{ range (.Paginate .Pages).Pages }} &amp;lt;h2&amp;gt;&amp;lt;a href=&amp;#34;{{ .RelPermalink }}&amp;#34;&amp;gt;{{ .LinkTitle }}&amp;lt;/a&amp;gt;&amp;lt;/h2&amp;gt; {{ end }} {{ template &amp;#34;_internal/pagination.html&amp;#34; . }} You can also use the template function to execute a defined template:
{{ template &amp;#34;foo&amp;#34; (dict &amp;#34;answer&amp;#34; 42) }} {{ define &amp;#34;foo&amp;#34; }} {{ printf &amp;#34;The answer is %v.&amp;#34; .answer }} {{ end }} The example above can be rewritten using an inline partial template:</description></item><item><title>urlquery</title><link>https://v0-122-0--gohugoio.netlify.app/functions/go-template/urlquery/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/go-template/urlquery/</guid><description>This template code:
{{ $u := urlquery &amp;#34;https://&amp;#34; &amp;#34;example.com&amp;#34; | safeURL }} &amp;lt;a href=&amp;#34;https://example.org?url={{ $u }}&amp;#34;&amp;gt;Link&amp;lt;/a&amp;gt; Is rendered to:
&amp;lt;a href=&amp;#34;https://example.org?url=https%3A%2F%2Fexample.com&amp;#34;&amp;gt;Link&amp;lt;/a&amp;gt; See Go&amp;rsquo;s text/template documentation for more information.</description></item><item><title>with</title><link>https://v0-122-0--gohugoio.netlify.app/functions/go-template/with/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/functions/go-template/with/</guid><description>In Go templates, the falsy values are false, 0, any nil pointer or interface value, and any array, slice, map, or string of length zero. Everything else is truthy.
{{ $var := &amp;#34;foo&amp;#34; }} {{ with $var }} {{ . }} → foo {{ end }} Use with the else statement:
{{ $var := &amp;#34;foo&amp;#34; }} {{ with $var }} {{ . }} → foo {{ else }} {{ print &amp;#34;var is falsy&amp;#34; }} {{ end }} Initialize a variable, scoped to the current block:</description></item></channel></rss>