diff options
Diffstat (limited to 'docs/content/en/methods/shortcode')
-rw-r--r-- | docs/content/en/methods/shortcode/Get.md | 51 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/Inner.md | 154 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/InnerDeindent.md | 99 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/IsNamedParams.md | 30 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/Name.md | 29 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/Ordinal.md | 50 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/Page.md | 36 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/Params.md | 33 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/Parent.md | 50 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/Position.md | 33 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/Ref.md | 44 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/RelRef.md | 44 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/Scratch.md | 24 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/Site.md | 19 | ||||
-rw-r--r-- | docs/content/en/methods/shortcode/_index.md | 12 |
15 files changed, 708 insertions, 0 deletions
diff --git a/docs/content/en/methods/shortcode/Get.md b/docs/content/en/methods/shortcode/Get.md new file mode 100644 index 000000000..8874c7649 --- /dev/null +++ b/docs/content/en/methods/shortcode/Get.md @@ -0,0 +1,51 @@ +--- +title: Get +description: Returns the value of the given argument. +categories: [] +keywords: [] +action: + related: + - methods/shortcode/IsNamedParams + - methods/shortcode/Params + returnType: any + signatures: [SHORTCODE.Get ARG] +toc: true +--- + +Specify the argument by position or by name. When calling a shortcode within Markdown, use either positional or named argument, but not both. + +{{% note %}} +Some shortcodes support positional arguments, some support named arguments, and others support both. Refer to the shortcode's documentation for usage details. +{{% /note %}} + +## Positional arguments + +This shortcode call uses positional arguments: + +{{< code file=content/about.md lang=md >}} +{{</* myshortcode "Hello" "world" */>}} +{{< /code >}} + +To retrieve arguments by position: + +{{< code file=layouts/shortcodes/myshortcode.html >}} +{{ printf "%s %s." (.Get 0) (.Get 1) }} → Hello world. +{{< /code >}} + +## Named arguments + +This shortcode call uses named arguments: + +{{< code file=content/about.md lang=md >}} +{{</* myshortcode greeting="Hello" firstName="world" */>}} +{{< /code >}} + +To retrieve arguments by name: + +{{< code file=layouts/shortcodes/myshortcode.html >}} +{{ printf "%s %s." (.Get "greeting") (.Get "firstName") }} → Hello world. +{{< /code >}} + +{{% note %}} +Argument names are case-sensitive. +{{% /note %}} diff --git a/docs/content/en/methods/shortcode/Inner.md b/docs/content/en/methods/shortcode/Inner.md new file mode 100644 index 000000000..2814bcc2a --- /dev/null +++ b/docs/content/en/methods/shortcode/Inner.md @@ -0,0 +1,154 @@ +--- +title: Inner +description: Returns the content between opening and closing shortcode tags, applicable when the shortcode call includes a closing tag. +categories: [] +keywords: [] +action: + related: + - functions/strings/Trim + - methods/page/RenderString + - functions/transform/Markdownify + - methods/shortcode/InnerDeindent + returnType: template.HTML + signatures: [SHORTCODE.Inner] +toc: true +--- + +This content: + +{{< code file=content/services.md lang=md >}} +{{</* card title="Product Design" */>}} +We design the **best** widgets in the world. +{{</* /card */>}} +{{< /code >}} + +With this shortcode: + +{{< code file=layouts/shortcodes/card.html >}} +<div class="card"> + {{ with .Get "title" }} + <div class="card-title">{{ . }}</div> + {{ end }} + <div class="card-content"> + {{ .Inner | strings.TrimSpace }} + </div> +</div> +{{< /code >}} + +Is rendered to: + +```html +<div class="card"> + <div class="card-title">Product Design</div> + <div class="card-content"> + We design the **best** widgets in the world. + </div> +</div> +``` + +{{% note %}} +Content between opening and closing shortcode tags may include leading and/or trailing newlines, depending on placement within the Markdown. Use the [`strings.TrimSpace`] function as shown above to remove both carriage returns and newlines. + +[`strings.TrimSpace`]: /functions/strings/trimspace/ +{{% /note %}} + +{{% note %}} +In the example above, the value returned by `Inner` is Markdown, but it was rendered as plain text. Use either of the following approaches to render Markdown to HTML. +{{% /note %}} + + +## Use RenderString + +Let's modify the example above to pass the value returned by `Inner` through the [`RenderString`] method on the `Page` object: + +[`RenderString`]: /methods/page/renderstring/ + +{{< code file=layouts/shortcodes/card.html >}} +<div class="card"> + {{ with .Get "title" }} + <div class="card-title">{{ . }}</div> + {{ end }} + <div class="card-content"> + {{ .Inner | strings.TrimSpace | .Page.RenderString }} + </div> +</div> +{{< /code >}} + +Hugo renders this to: + +```html +<div class="card"> + <div class="card-title">Product design</div> + <div class="card-content"> + We produce the <strong>best</strong> widgets in the world. + </div> +</div> +``` + +You can use the [`markdownify`] function instead of the `RenderString` method, but the latter is more flexible. See [details]. + +[details]: /methods/page/renderstring/ +[`markdownify`]: /functions/transform/markdownify/ + +## Alternative notation + +Instead of calling the shortcode with the `{{</* */>}}` notation, use the `{{%/* */%}}` notation: + +{{< code file=content/services.md lang=md >}} +{{%/* card title="Product Design" */%}} +We design the **best** widgets in the world. +{{%/* /card */%}} +{{< /code >}} + +When you use the `{{%/* */%}}` notation, Hugo renders the entire shortcode as Markdown, requiring the following changes. + +First, configure the renderer to allow raw HTML within Markdown: + +{{< code-toggle file=hugo >}} +[markup.goldmark.renderer] +unsafe = true +{{< /code-toggle >}} + +This configuration is not unsafe if _you_ control the content. Read more about Hugo's [security model]. + +Second, because we are rendering the entire shortcode as Markdown, we must adhere to the rules governing [indentation] and inclusion of [raw HTML blocks] as provided in the [CommonMark] specification. + +{{< code file=layouts/shortcodes/card.html >}} +<div class="card"> + {{ with .Get "title" }} + <div class="card-title">{{ . }}</div> + {{ end }} + <div class="card-content"> + + {{ .Inner | strings.TrimSpace }} + </div> +</div> +{{< /code >}} + +The difference between this and the previous example is subtle but required. Note the change in indentation, the addition of a blank line, and removal of the `RenderString` method. + +```diff +--- layouts/shortcodes/a.html ++++ layouts/shortcodes/b.html +@@ -1,8 +1,9 @@ + <div class="card"> + {{ with .Get "title" }} +- <div class="card-title">{{ . }}</div> ++ <div class="card-title">{{ . }}</div> + {{ end }} + <div class="card-content"> +- {{ .Inner | strings.TrimSpace | .Page.RenderString }} ++ ++ {{ .Inner | strings.TrimSpace }} + </div> + </div> +``` + +{{% note %}} +When using the `{{%/* */%}}` notation, do not pass the value returned by `Inner` through the `RenderString` method or the `markdownify` function. +{{% /note %}} + +[commonmark]: https://commonmark.org/ +[indentation]: https://spec.commonmark.org/0.30/#indented-code-blocks +[raw html blocks]: https://spec.commonmark.org/0.30/#html-blocks +[security model]: /about/security/ diff --git a/docs/content/en/methods/shortcode/InnerDeindent.md b/docs/content/en/methods/shortcode/InnerDeindent.md new file mode 100644 index 000000000..ab4263709 --- /dev/null +++ b/docs/content/en/methods/shortcode/InnerDeindent.md @@ -0,0 +1,99 @@ +--- +title: InnerDeindent +description: Returns the content between opening and closing shortcode tags, with indentation removed, applicable when the shortcode call includes a closing tag. +categories: [] +keywords: [] +action: + related: + - methods/shortcode/Inner + returnType: template.HTML + signatures: [SHORTCODE.InnerDeindent] +--- + +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: + +{{< code file=content/about.md lang=md >}} +- Gallery one + + {{</* gallery */>}} +  +  + {{</* /gallery */>}} + +- Gallery two + + {{</* gallery */>}} +  +  + {{</* /gallery */>}} +{{< /code >}} + +In the example above, notice that the content between the opening and closing shortcode tags is indented by four spaces. Per the CommonMark specification, this is treated as an indented code block. + +With this shortcode, calling `Inner` instead of `InnerDeindent`: + +{{< code file=layouts/shortcodes/gallery.html >}} +<div class="gallery"> + {{ .Inner | strings.TrimSpace | .Page.RenderString }} +</div> +{{< /code >}} + +Hugo renders the Markdown to: + +```html +<ul> + <li> + <p>Gallery one</p> + <div class="gallery"> + <pre><code> +  + </code></pre> + </div> + </li> + <li> + <p>Gallery two</p> + <div class="gallery"> + <pre><code> +  + </code></pre> + </div> + </li> +</ul> +``` + +Although technically correct per the CommonMark specification, this is not what we want. If we remove the indentation using the `InnerDeindent` method: + +{{< code file=layouts/shortcodes/gallery.html >}} +<div class="gallery"> + {{ .InnerDeindent | strings.TrimSpace | .Page.RenderString }} +</div> +{{< /code >}} + +Hugo renders the Markdown to: + +```html +<ul> + <li> + <p>Gallery one</p> + <div class="gallery"> + <img src="images/a.jpg" alt="kitten a"> + <img src="images/b.jpg" alt="kitten b"> + </div> + </li> + <li> + <p>Gallery two</p> + <div class="gallery"> + <img src="images/c.jpg" alt="kitten c"> + <img src="images/d.jpg" alt="kitten d"> + </div> + </li> +</ul> +``` + +[commonmark]: https://commonmark.org/ +[indentation]: https://spec.commonmark.org/0.30/#indented-code-blocks +[`Inner`]: /methods/shortcode/inner/ diff --git a/docs/content/en/methods/shortcode/IsNamedParams.md b/docs/content/en/methods/shortcode/IsNamedParams.md new file mode 100644 index 000000000..a1d93ddac --- /dev/null +++ b/docs/content/en/methods/shortcode/IsNamedParams.md @@ -0,0 +1,30 @@ +--- +title: IsNamedParams +description: Reports whether the shortcode call uses named arguments. +categories: [] +keywords: [] +action: + related: + - methods/shortcode/Get + returnType: bool + signatures: [SHORTCODE.IsNamedParams] +--- + +To support both positional and named arguments when calling a shortcode, use the `IsNamedParams` method to determine how the shortcode was called. + +With this shortcode template: + +{{< code file=layouts/shortcodes/myshortcode.html >}} +{{ if .IsNamedParams }} + {{ printf "%s %s." (.Get "greeting") (.Get "firstName") }} +{{ else }} + {{ printf "%s %s." (.Get 0) (.Get 1) }} +{{ end }} +{{< /code >}} + +Both of these calls return the same value: + +{{< code file=content/about.md lang=md >}} +{{</* myshortcode greeting="Hello" firstName="world" */>}} +{{</* myshortcode "Hello" "world" */>}} +{{< /code >}} diff --git a/docs/content/en/methods/shortcode/Name.md b/docs/content/en/methods/shortcode/Name.md new file mode 100644 index 000000000..fcf92718f --- /dev/null +++ b/docs/content/en/methods/shortcode/Name.md @@ -0,0 +1,29 @@ +--- +title: Name +description: Returns the shortcode file name, excluding the file extension. +categories: [] +keywords: [] +action: + related: + - methods/shortcode/Position + - functions/fmt/Errorf + returnType: string + signatures: [SHORTCODE.Name] +--- + +The `Name` method is useful for error reporting. For example, if your shortcode requires a "greeting" argument: + +{{< code file=layouts/shortcodes/myshortcode.html >}} +{{ $greeting := "" }} +{{ with .Get "greeting" }} + {{ $greeting = . }} +{{ else }} + {{ errorf "The %q shortcode requires a 'greeting' argument. See %s" .Name .Position }} +{{ end }} +{{< /code >}} + +In the absence of a "greeting" argument, Hugo will throw an error message and fail the build: + +```text +ERROR The "myshortcode" shortcode requires a 'greeting' argument. See "/home/user/project/content/about.md:11:1" +``` diff --git a/docs/content/en/methods/shortcode/Ordinal.md b/docs/content/en/methods/shortcode/Ordinal.md new file mode 100644 index 000000000..6f3580d0f --- /dev/null +++ b/docs/content/en/methods/shortcode/Ordinal.md @@ -0,0 +1,50 @@ +--- +title: Ordinal +description: Returns the zero-based ordinal of the shortcode in relation to its parent. +categories: [] +keywords: [] +action: + related: [] + returnType: int + signatures: [SHORTCODE.Ordinal] +--- + +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: + +{{< code file=content/about.md lang=md >}} +{{</* img src="images/a.jpg" */>}} + +{{</* img src="images/b.jpg" */>}} +{{< /code >}} + +This shortcode performs error checking, then renders an HTML `img` element with a unique `id` attribute: + +{{< code file=layouts/shortcodes/img.html >}} +{{ $src := "" }} +{{ with .Get "src" }} + {{ $src = . }} + {{ with resources.Get $src }} + {{ $id := printf "img-%03d" $.Ordinal }} + <img id="{{ $id }}" src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt=""> + {{ else }} + {{ errorf "The %q shortcode was unable to find %s. See %s" $.Name $src $.Position }} + {{ end }} +{{ else }} + {{ errorf "The %q shortcode requires a 'src' argument. See %s" .Name .Position }} +{{ end }} +{{< /code >}} + +Hugo renders the page to: + +```html +<img id="img-000" src="/images/a.jpg" width="600" height="400" alt=""> +<img id="img-001" src="/images/b.jpg" width="600" height="400" alt=""> +``` + +{{% note %}} +In the shortcode template above, the [`with`] statement is used to create conditional blocks. Remember that the `with` statement binds context (the dot) to its expression. Inside of a `with` block, preface shortcode method calls with a `$` to access the top level context passed into the template. + +[`with`]: /functions/go-template/with/ +{{% /note %}} diff --git a/docs/content/en/methods/shortcode/Page.md b/docs/content/en/methods/shortcode/Page.md new file mode 100644 index 000000000..8bb58fa18 --- /dev/null +++ b/docs/content/en/methods/shortcode/Page.md @@ -0,0 +1,36 @@ +--- +title: Page +description: Returns the Page object from which the shortcode was called. +categories: [] +keywords: [] +action: + related: [] + returnType: hugolib.pageForShortcode + signatures: [SHORTCODE.Page] +--- + +With this content: + +{{< code-toggle file=content/books/les-miserables.md fm=true >}} +title = 'Les Misérables' +author = 'Victor Hugo' +publication_year = 1862 +isbn = '978-0451419439' +{{< /code-toggle >}} + +Calling this shortcode: + +```text +{{</* book-details */>}} +``` + +We can access the front matter values using the `Page` method: + +{{< code file=layouts/shortcodes/book-details.html >}} +<ul> + <li>Title: {{ .Page.Title }}</li> + <li>Author: {{ .Page.Params.author }}</li> + <li>Published: {{ .Page.Params.publication_year }}</li> + <li>ISBN: {{ .Page.Params.isbn }}</li> +</ul> +{{< /code >}} diff --git a/docs/content/en/methods/shortcode/Params.md b/docs/content/en/methods/shortcode/Params.md new file mode 100644 index 000000000..c0772e36a --- /dev/null +++ b/docs/content/en/methods/shortcode/Params.md @@ -0,0 +1,33 @@ +--- +title: Params +description: Returns a collection of the shortcode arguments. +categories: [] +keywords: [] +action: + related: + - methods/shortcode/Get + returnType: any + signatures: [SHORTCODE.Params] +--- + +When you call a shortcode using positional arguments, the `Params` method returns a slice. + +{{< code file=content/about.md lang=md >}} +{{</* myshortcode "Hello" "world" */>}} +{{< /code >}} + +{{< code file=layouts/shortcodes/myshortcode.html >}} +{{ index .Params 0 }} → Hello +{{ index .Params 1 }} → world +{{< /code >}} + +When you call a shortcode using named arguments, the `Params` method returns a map. + +{{< code file=content/about.md lang=md >}} +{{</* myshortcode greeting="Hello" name="world" */>}} +{{< /code >}} + +{{< code file=layouts/shortcodes/myshortcode.html >}} +{{ .Params.greeting }} → Hello +{{ .Params.name }} → world +{{< /code >}} diff --git a/docs/content/en/methods/shortcode/Parent.md b/docs/content/en/methods/shortcode/Parent.md new file mode 100644 index 000000000..53fac8237 --- /dev/null +++ b/docs/content/en/methods/shortcode/Parent.md @@ -0,0 +1,50 @@ +--- +title: Parent +description: Returns the parent shortcode context in nested shortcodes. +categories: [] +keywords: [] +action: + related: [] + returnType: hugolib.ShortcodeWithPage + signatures: [SHORTCODE.Parent] +--- + +This is useful for inheritance of common shortcode arguments from the root. + +In this contrived example, the "greeting" shortcode is the parent, and the "now" shortcode is child. + +{{< code file=content/welcome.md lang=md >}} +{{</* greeting dateFormat="Jan 2, 2006" */>}} +Welcome. Today is {{</* now */>}}. +{{</* /greeting */>}} +{{< /code >}} + +{{< code file=layouts/shortcodes/greeting.html >}} +<div class="greeting"> + {{ .Inner | strings.TrimSpace | .Page.RenderString }} +</div> +{{< /code >}} + +{{< code file=layouts/shortcodes/now.html >}} +{{- $dateFormat := "January 2, 2006 15:04:05" }} + +{{- with .Params }} + {{- with .dateFormat }} + {{- $dateFormat = . }} + {{- end }} +{{- else }} + {{- with .Parent.Params }} + {{- with .dateFormat }} + {{- $dateFormat = . }} + {{- end }} + {{- end }} +{{- end }} + +{{- now | time.Format $dateFormat -}} +{{< /code >}} + +The "now" shortcode formats the current time using: + +1. The `dateFormat` argument passed to the "now" shortcode, if present +2. The `dateFormat` argument passed to the "greeting" shortcode, if present +3. The default layout string defined at the top of the shortcode diff --git a/docs/content/en/methods/shortcode/Position.md b/docs/content/en/methods/shortcode/Position.md new file mode 100644 index 000000000..6f047c01b --- /dev/null +++ b/docs/content/en/methods/shortcode/Position.md @@ -0,0 +1,33 @@ +--- +title: Position +description: Returns the filename and position from which the shortcode was called. +categories: [] +keywords: [] +action: + related: + - methods/shortcode/Name + - functions/fmt/Errorf + returnType: text.Position + signatures: [SHORTCODE.Position] +--- + +The `Position` method is useful for error reporting. For example, if your shortcode requires a "greeting" argument: + +{{< code file=layouts/shortcodes/myshortcode.html >}} +{{ $greeting := "" }} +{{ with .Get "greeting" }} + {{ $greeting = . }} +{{ else }} + {{ errorf "The %q shortcode requires a 'greeting' argument. See %s" .Name .Position }} +{{ end }} +{{< /code >}} + +In the absence of a "greeting" argument, Hugo will throw an error message and fail the build: + +```text +ERROR The "myshortcode" shortcode requires a 'greeting' argument. See "/home/user/project/content/about.md:11:1" +``` + +{{% note %}} +The position can be expensive to calculate. Limit its use to error reporting. +{{% /note %}} diff --git a/docs/content/en/methods/shortcode/Ref.md b/docs/content/en/methods/shortcode/Ref.md new file mode 100644 index 000000000..293c772d9 --- /dev/null +++ b/docs/content/en/methods/shortcode/Ref.md @@ -0,0 +1,44 @@ +--- +title: Ref +description: Returns the absolute URL of the page with the given path, language, and output format. +categories: [] +keywords: [] +action: + related: + - methods/shortcode/RelRef + - functions/urls/RelRef + - functions/urls/Ref + returnType: string + signatures: [SHORTCODE.Ref OPTIONS] +--- + +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: + +```go-html-template +{{ $opts := dict "path" "/books/book-1" }} +{{ .Ref $opts }} → https://example.org/en/books/book-1/ + +{{ $opts := dict "path" "/books/book-1" "lang" "de" }} +{{ .Ref $opts }} → https://example.org/de/books/book-1/ + +{{ $opts := dict "path" "/books/book-1" "lang" "de" "outputFormat" "json" }} +{{ .Ref $opts }} → https://example.org/de/books/book-1/index.json +``` + +By default, Hugo will throw an error and fail the build if it cannot resolve the path. You can change this to a warning in your site configuration, and specify a URL to return when the path cannot be resolved. + +{{< code-toggle file=hugo >}} +refLinksErrorLevel = 'warning' +refLinksNotFoundURL = '/some/other/url' +{{< /code-toggle >}} diff --git a/docs/content/en/methods/shortcode/RelRef.md b/docs/content/en/methods/shortcode/RelRef.md new file mode 100644 index 000000000..07f221a99 --- /dev/null +++ b/docs/content/en/methods/shortcode/RelRef.md @@ -0,0 +1,44 @@ +--- +title: RelRef +description: Returns the relative URL of the page with the given path, language, and output format. +categories: [] +keywords: [] +action: + related: + - methods/shortcode/Ref + - functions/urls/Ref + - functions/urls/RelRef + returnType: string + signatures: [SHORTCODE.RelRef OPTIONS] +--- + +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: + +```go-html-template +{{ $opts := dict "path" "/books/book-1" }} +{{ .RelRef $opts }} → /en/books/book-1/ + +{{ $opts := dict "path" "/books/book-1" "lang" "de" }} +{{ .RelRef $opts }} → /de/books/book-1/ + +{{ $opts := dict "path" "/books/book-1" "lang" "de" "outputFormat" "json" }} +{{ .RelRef $opts }} → /de/books/book-1/index.json +``` + +By default, Hugo will throw an error and fail the build if it cannot resolve the path. You can change this to a warning in your site configuration, and specify a URL to return when the path cannot be resolved. + +{{< code-toggle file=hugo >}} +refLinksErrorLevel = 'warning' +refLinksNotFoundURL = '/some/other/url' +{{< /code-toggle >}} diff --git a/docs/content/en/methods/shortcode/Scratch.md b/docs/content/en/methods/shortcode/Scratch.md new file mode 100644 index 000000000..fcfc99d53 --- /dev/null +++ b/docs/content/en/methods/shortcode/Scratch.md @@ -0,0 +1,24 @@ +--- +title: Scratch +description: Returns a "scratch pad" scoped to the shortcode to store and manipulate data. +categories: [] +keywords: [] +action: + related: + - functions/collections/NewScratch + returnType: maps.Scratch + signatures: [SHORTCODE.Scratch] +--- + +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. + +{{% note %}} +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. + +[assign values to template variables]: https://go.dev/doc/go1.11#text/template +[`newScratch`]: /functions/collections/newscratch/ +{{% /note %}} + +[scratch pad]: /getting-started/glossary/#scratch-pad + +{{% include "methods/page/_common/scratch-methods.md" %}} diff --git a/docs/content/en/methods/shortcode/Site.md b/docs/content/en/methods/shortcode/Site.md new file mode 100644 index 000000000..af2a755ee --- /dev/null +++ b/docs/content/en/methods/shortcode/Site.md @@ -0,0 +1,19 @@ +--- +title: Site +description: Returns the Site object. +categories: [] +keywords: [] +action: + related: + - methods/page/Sites + returnType: page.siteWrapper + signatures: [SHORTCODE.Site] +--- + +See [Site methods]. + +[Site methods]: /methods/site/ + +```go-html-template +{{ .Site.Title }} +``` diff --git a/docs/content/en/methods/shortcode/_index.md b/docs/content/en/methods/shortcode/_index.md new file mode 100644 index 000000000..d26366844 --- /dev/null +++ b/docs/content/en/methods/shortcode/_index.md @@ -0,0 +1,12 @@ +--- +title: Shortcode methods +linkTitle: Shortcode +description: Use these methods in your shortcode templates. +categories: [] +keywords: [] +menu: + docs: + parent: methods +--- + +Use these methods in your shortcode templates. |