<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Shortcode methods on Hugo</title><link>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/</link><description>Recent content in Shortcode methods on Hugo</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="https://v0-122-0--gohugoio.netlify.app/methods/shortcode/index.xml" rel="self" type="application/rss+xml"/><item><title>Get</title><link>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/get/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/get/</guid><description>Specify the parameter by position or by name. When calling a shortcode within markdown, use either positional or named parameters, but not both.
Some shortcodes support positional parameters, some support named parameters, and others support both. Refer to the shortcode&amp;rsquo;s documentation for usage details.
Positional parameters This shortcode call uses positional parameters:
content/about.md {{&amp;lt; myshortcode &amp;#34;Hello&amp;#34; &amp;#34;world&amp;#34; &amp;gt;}} To retrieve parameters by position:
layouts/shortcodes/myshortcode.html {{ printf &amp;#34;%s %s.&amp;#34; (.Get 0) (.</description></item><item><title>Inner</title><link>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/inner/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/inner/</guid><description>This content:
content/services.md {{&amp;lt; card title=&amp;#34;Product Design&amp;#34; &amp;gt;}} We design the **best** widgets in the world. {{&amp;lt; /card &amp;gt;}} With this shortcode:
layouts/shortcodes/card.html &amp;lt;div class=&amp;#34;card&amp;#34;&amp;gt; {{ with .Get &amp;#34;title&amp;#34; }} &amp;lt;div class=&amp;#34;card-title&amp;#34;&amp;gt;{{ . }}&amp;lt;/div&amp;gt; {{ end }} &amp;lt;div class=&amp;#34;card-content&amp;#34;&amp;gt; {{ trim .Inner &amp;#34;\r\n&amp;#34; }} &amp;lt;/div&amp;gt; &amp;lt;/div&amp;gt; Is rendered to:
&amp;lt;div class=&amp;#34;card&amp;#34;&amp;gt; &amp;lt;div class=&amp;#34;card-title&amp;#34;&amp;gt;Product Design&amp;lt;/div&amp;gt; &amp;lt;div class=&amp;#34;card-content&amp;#34;&amp;gt; We design the **best** widgets in the world. &amp;lt;/div&amp;gt; &amp;lt;/div&amp;gt; Content between opening and closing shortcode tags may include leading and/or trailing newlines, depending on placement within the markdown.</description></item><item><title>InnerDeindent</title><link>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/innerdeindent/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/innerdeindent/</guid><description>Similar to the Inner method, InnerDeindent returns the content between opening and closing shortcode tags. However, with InnerDeindent, indentation before the content is removed.
This allows us to effectively bypass the rules governing indentation as provided in the CommonMark specification.
Consider this markdown, an unordered list with a small gallery of thumbnail images within each list item:
content/about.md - Gallery one {{&amp;lt; gallery &amp;gt;}} ![kitten a](thumbnails/a.jpg) ![kitten b](thumbnails/b.jpg) {{&amp;lt; /gallery &amp;gt;}} - Gallery two {{&amp;lt; gallery &amp;gt;}} !</description></item><item><title>IsNamedParams</title><link>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/isnamedparams/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/isnamedparams/</guid><description>To support both positional and named parameters when calling a shortcode, use the IsNamedParams method to determine how the shortcode was called.
With this shortcode template:
layouts/shortcodes/myshortcode.html {{ if .IsNamedParams }} {{ printf &amp;#34;%s %s.&amp;#34; (.Get &amp;#34;greeting&amp;#34;) (.Get &amp;#34;firstName&amp;#34;) }} {{ else }} {{ printf &amp;#34;%s %s.&amp;#34; (.Get 0) (.Get 1) }} {{ end }} Both of these calls return the same value:
content/about.md {{&amp;lt; myshortcode greeting=&amp;#34;Hello&amp;#34; firstName=&amp;#34;world&amp;#34; &amp;gt;}} {{&amp;lt; myshortcode &amp;#34;Hello&amp;#34; &amp;#34;world&amp;#34; &amp;gt;}}</description></item><item><title>Name</title><link>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/name/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/name/</guid><description>The Name method is useful for error reporting. For example, if your shortcode requires a &amp;ldquo;greeting&amp;rdquo; parameter:
layouts/shortcodes/myshortcode.html {{ $greeting := &amp;#34;&amp;#34; }} {{ with .Get &amp;#34;greeting&amp;#34; }} {{ $greeting = . }} {{ else }} {{ errorf &amp;#34;The %q shortcode requires a &amp;#39;greeting&amp;#39; parameter. See %s&amp;#34; .Name .Position }} {{ end }} In the absence of a &amp;ldquo;greeting&amp;rdquo; parameter, Hugo will throw an error message and fail the build:</description></item><item><title>Ordinal</title><link>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/ordinal/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/ordinal/</guid><description>The Ordinal method returns the zero-based ordinal of the shortcode in relation to its parent. If the parent is the page itself, the ordinal represents the position of this shortcode in the page content.
This method is useful for, among other things, assigning unique element IDs when a shortcode is called two or more times from the same page. For example:
content/about.md {{&amp;lt; img src=&amp;#34;images/a.jpg&amp;#34; &amp;gt;}} {{&amp;lt; img src=&amp;#34;images/b.jpg&amp;#34; &amp;gt;}} This shortcode performs error checking, then renders an HTML img element with a unique id attribute:</description></item><item><title>Page</title><link>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/page/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/page/</guid><description>With this content:
content/books/les-miserables.md yaml &amp;nbsp; toml &amp;nbsp; json &amp;nbsp; --- author: Victor Hugo isbn: 978-0451419439 publication_year: 1862 title: Les Misérables --- +++ author = &amp;#39;Victor Hugo&amp;#39; isbn = &amp;#39;978-0451419439&amp;#39; publication_year = 1862 title = &amp;#39;Les Misérables&amp;#39; +++ { &amp;#34;author&amp;#34;: &amp;#34;Victor Hugo&amp;#34;, &amp;#34;isbn&amp;#34;: &amp;#34;978-0451419439&amp;#34;, &amp;#34;publication_year&amp;#34;: 1862, &amp;#34;title&amp;#34;: &amp;#34;Les Misérables&amp;#34; } Calling this shortcode:
{{&amp;lt; book-details &amp;gt;}} We can access the front matter values using the Page method:
layouts/shortcodes/book-details.html &amp;lt;ul&amp;gt; &amp;lt;li&amp;gt;Title: {{ .</description></item><item><title>Params</title><link>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/params/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/params/</guid><description>When you call a shortcode using positional parameters, the Params method returns a slice.
content/about.md {{&amp;lt; myshortcode &amp;#34;Hello&amp;#34; &amp;#34;world&amp;#34; &amp;gt;}} layouts/shortcodes/myshortcode.html {{ index .Params 0 }} → Hello {{ index .Params 1 }} → world When you call a shortcode using named parameters, the Params method returns a map.
content/about.md {{&amp;lt; myshortcode greeting=&amp;#34;Hello&amp;#34; name=&amp;#34;world&amp;#34; &amp;gt;}} layouts/shortcodes/myshortcode.html {{ .Params.greeting }} → Hello {{ .Params.name }} → world</description></item><item><title>Parent</title><link>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/parent/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/parent/</guid><description>This is useful for inheritance of common shortcode parameters from the root.
In this contrived example, the &amp;ldquo;greeting&amp;rdquo; shortcode is the parent, and the &amp;ldquo;now&amp;rdquo; shortcode is child.
content/welcome.md {{&amp;lt; greeting dateFormat=&amp;#34;Jan 2, 2006&amp;#34; &amp;gt;}} Welcome. Today is {{&amp;lt; now &amp;gt;}}. {{&amp;lt; /greeting &amp;gt;}} layouts/shortcodes/greeting.html &amp;lt;div class=&amp;#34;greeting&amp;#34;&amp;gt; {{ trim .Inner &amp;#34;\r\n&amp;#34; | .Page.RenderString }} &amp;lt;/div&amp;gt; layouts/shortcodes/now.html {{- $dateFormat := &amp;#34;January 2, 2006 15:04:05&amp;#34; }} {{- with .Params }} {{- with .</description></item><item><title>Position</title><link>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/position/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/position/</guid><description>The Position method is useful for error reporting. For example, if your shortcode requires a &amp;ldquo;greeting&amp;rdquo; parameter:
layouts/shortcodes/myshortcode.html {{ $greeting := &amp;#34;&amp;#34; }} {{ with .Get &amp;#34;greeting&amp;#34; }} {{ $greeting = . }} {{ else }} {{ errorf &amp;#34;The %q shortcode requires a &amp;#39;greeting&amp;#39; parameter. See %s&amp;#34; .Name .Position }} {{ end }} In the absence of a &amp;ldquo;greeting&amp;rdquo; parameter, Hugo will throw an error message and fail the build:</description></item><item><title>Ref</title><link>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/ref/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/ref/</guid><description>The map of option contains:
path (string) The path to the page, relative to the content directory. Required. lang (string) The language (site) to search for the page. Default is the current language. Optional. outputFormat (string) The output format to search for the page. Default is the current output format. Optional. The examples below show the rendered output when visiting a page on the English language version of the site:</description></item><item><title>RelRef</title><link>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/relref/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/relref/</guid><description>The map of option contains:
path (string) The path to the page, relative to the content directory. Required. lang (string) The language (site) to search for the page. Default is the current language. Optional. outputFormat (string) The output format to search for the page. Default is the current output format. Optional. The examples below show the rendered output when visiting a page on the English language version of the site:</description></item><item><title>Scratch</title><link>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/scratch/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/scratch/</guid><description>The Scratch method within a shortcode creates a scratch pad to store and manipulate data. The scratch pad is scoped to the shortcode, and is reset on server rebuilds.
With the introduction of the newScratch function, and the ability to assign values to template variables after initialization, the Scratch method within a shortcode is obsolete.
Methods Set Sets the value of a given key.
{{ .Scratch.Set &amp;#34;greeting&amp;#34; &amp;#34;Hello&amp;#34; }} Get Gets the value of a given key.</description></item><item><title>Site</title><link>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/site/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://v0-122-0--gohugoio.netlify.app/methods/shortcode/site/</guid><description>See Site methods.
{{ .Site.Title }}</description></item></channel></rss>