mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-29 15:10:35 +03:00
Merge commit '8b9803425e
'
This commit is contained in:
commit
af0cb57aaf
475 changed files with 7408 additions and 4720 deletions
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
title: Get
|
||||
description: Returns the value of the given parameter.
|
||||
description: Returns the value of the given argument.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
|
@ -8,44 +8,44 @@ action:
|
|||
- methods/shortcode/IsNamedParams
|
||||
- methods/shortcode/Params
|
||||
returnType: any
|
||||
signatures: [SHORTCODE.Get PARAM]
|
||||
signatures: [SHORTCODE.Get ARG]
|
||||
toc: true
|
||||
---
|
||||
|
||||
Specify the parameter by position or by name. When calling a shortcode within markdown, use either positional or named parameters, but not both.
|
||||
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 parameters, some support named parameters, and others support both. Refer to the shortcode's documentation for usage details.
|
||||
Some shortcodes support positional arguments, some support named arguments, and others support both. Refer to the shortcode's documentation for usage details.
|
||||
{{% /note %}}
|
||||
|
||||
## Positional parameters
|
||||
## Positional arguments
|
||||
|
||||
This shortcode call uses positional parameters:
|
||||
This shortcode call uses positional arguments:
|
||||
|
||||
{{< code file=content/about.md lang=md >}}
|
||||
{{</* myshortcode "Hello" "world" */>}}
|
||||
{{< /code >}}
|
||||
|
||||
To retrieve parameters by position:
|
||||
To retrieve arguments by position:
|
||||
|
||||
{{< code file=layouts/shortcodes/myshortcode.html >}}
|
||||
{{ printf "%s %s." (.Get 0) (.Get 1) }} → Hello world.
|
||||
{{< /code >}}
|
||||
|
||||
## Named parameters
|
||||
## Named arguments
|
||||
|
||||
This shortcode call uses named parameters:
|
||||
This shortcode call uses named arguments:
|
||||
|
||||
{{< code file=content/about.md lang=md >}}
|
||||
{{</* myshortcode greeting="Hello" firstName="world" */>}}
|
||||
{{< /code >}}
|
||||
|
||||
To retrieve parameters by name:
|
||||
To retrieve arguments by name:
|
||||
|
||||
{{< code file=layouts/shortcodes/myshortcode.html >}}
|
||||
{{ printf "%s %s." (.Get "greeting") (.Get "firstName") }} → Hello world.
|
||||
{{< /code >}}
|
||||
|
||||
{{% note %}}
|
||||
Parameter names are case-sensitive.
|
||||
Argument names are case-sensitive.
|
||||
{{% /note %}}
|
||||
|
|
|
@ -46,13 +46,13 @@ Is rendered to:
|
|||
```
|
||||
|
||||
{{% note %}}
|
||||
Content between opening and closing shortcode tags may include leading and/or trailing newlines, depending on placement within the markdown. Use the [`trim`] function as shown above to remove both carriage returns and newlines.
|
||||
Content between opening and closing shortcode tags may include leading and/or trailing newlines, depending on placement within the Markdown. Use the [`trim`] function as shown above to remove both carriage returns and newlines.
|
||||
|
||||
[`trim`]: /functions/strings/trim
|
||||
[`trim`]: /functions/strings/trim/
|
||||
{{% /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.
|
||||
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 %}}
|
||||
|
||||
|
||||
|
@ -60,7 +60,7 @@ In the example above, the value returned by `Inner` is markdown, but it was rend
|
|||
|
||||
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
|
||||
[`RenderString`]: /methods/page/renderstring/
|
||||
|
||||
{{< code file=layouts/shortcodes/card.html >}}
|
||||
<div class="card">
|
||||
|
@ -86,8 +86,8 @@ Hugo renders this to:
|
|||
|
||||
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
|
||||
[details]: /methods/page/renderstring/
|
||||
[`markdownify`]: /functions/transform/markdownify/
|
||||
|
||||
## Use alternate notation
|
||||
|
||||
|
@ -99,9 +99,9 @@ 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.
|
||||
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:
|
||||
First, configure the renderer to allow raw HTML within Markdown:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[markup.goldmark.renderer]
|
||||
|
@ -110,7 +110,7 @@ unsafe = true
|
|||
|
||||
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.
|
||||
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">
|
||||
|
@ -150,4 +150,4 @@ When using the `{{%/* */%}}` notation, do not pass the value returned by `Inner`
|
|||
[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-model/
|
||||
[security model]: /about/security/
|
||||
|
|
|
@ -14,7 +14,7 @@ Similar to the [`Inner`] method, `InnerDeindent` returns the content between ope
|
|||
|
||||
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:
|
||||
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
|
||||
|
@ -42,7 +42,7 @@ With this shortcode, calling `Inner` instead of `InnerDeindent`:
|
|||
</div>
|
||||
{{< /code >}}
|
||||
|
||||
Hugo renders the markdown to:
|
||||
Hugo renders the Markdown to:
|
||||
|
||||
```html
|
||||
<ul>
|
||||
|
@ -73,7 +73,7 @@ Although technically correct per the CommonMark specification, this is not what
|
|||
</div>
|
||||
{{< /code >}}
|
||||
|
||||
Hugo renders the markdown to:
|
||||
Hugo renders the Markdown to:
|
||||
|
||||
```html
|
||||
<ul>
|
||||
|
@ -96,4 +96,4 @@ Hugo renders the markdown to:
|
|||
|
||||
[commonmark]: https://commonmark.org/
|
||||
[indentation]: https://spec.commonmark.org/0.30/#indented-code-blocks
|
||||
[`Inner`]: /methods/shortcode/inner
|
||||
[`Inner`]: /methods/shortcode/inner/
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
title: IsNamedParams
|
||||
description: Reports whether the shortcode call uses named parameters.
|
||||
description: Reports whether the shortcode call uses named arguments.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
|
@ -10,7 +10,7 @@ action:
|
|||
signatures: [SHORTCODE.IsNamedParams]
|
||||
---
|
||||
|
||||
To support both positional and named parameters when calling a shortcode, use the `IsNamedParams` method to determine how the shortcode was called.
|
||||
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:
|
||||
|
||||
|
|
|
@ -11,19 +11,19 @@ action:
|
|||
signatures: [SHORTCODE.Name]
|
||||
---
|
||||
|
||||
The `Name` method is useful for error reporting. For example, if your shortcode requires a "greeting" parameter:
|
||||
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' parameter. See %s" .Name .Position }}
|
||||
{{ errorf "The %q shortcode requires a 'greeting' argument. See %s" .Name .Position }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
In the absence of a "greeting" parameter, Hugo will throw an error message and fail the build:
|
||||
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' parameter. See "/home/user/project/content/about.md:11:1"
|
||||
ERROR The "myshortcode" shortcode requires a 'greeting' argument. See "/home/user/project/content/about.md:11:1"
|
||||
```
|
||||
|
|
|
@ -32,7 +32,7 @@ This shortcode performs error checking, then renders an HTML `img` element with
|
|||
{{ errorf "The %q shortcode was unable to find %s. See %s" $.Name $src $.Position }}
|
||||
{{ end }}
|
||||
{{ else }}
|
||||
{{ errorf "The %q shortcode requires a 'src' parameter. See %s" .Name .Position }}
|
||||
{{ errorf "The %q shortcode requires a 'src' argument. See %s" .Name .Position }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
|
@ -46,5 +46,5 @@ Hugo renders the page to:
|
|||
{{% 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
|
||||
[`with`]: /functions/go-template/with/
|
||||
{{% /note %}}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
title: Params
|
||||
description: Returns a collection of the shortcode parameters.
|
||||
description: Returns a collection of the shortcode arguments.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
|
@ -10,7 +10,7 @@ action:
|
|||
signatures: [SHORTCODE.Params]
|
||||
---
|
||||
|
||||
When you call a shortcode using positional parameters, the `Params` method returns a slice.
|
||||
When you call a shortcode using positional arguments, the `Params` method returns a slice.
|
||||
|
||||
{{< code file=content/about.md lang=md >}}
|
||||
{{</* myshortcode "Hello" "world" */>}}
|
||||
|
@ -21,7 +21,7 @@ When you call a shortcode using positional parameters, the `Params` method retur
|
|||
{{ index .Params 1 }} → world
|
||||
{{< /code >}}
|
||||
|
||||
When you call a shortcode using named parameters, the `Params` method returns a map.
|
||||
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" */>}}
|
||||
|
|
|
@ -9,7 +9,7 @@ action:
|
|||
signatures: [SHORTCODE.Parent]
|
||||
---
|
||||
|
||||
This is useful for inheritance of common shortcode parameters from the root.
|
||||
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.
|
||||
|
||||
|
@ -45,6 +45,6 @@ Welcome. Today is {{</* now */>}}.
|
|||
|
||||
The "now" shortcode formats the current time using:
|
||||
|
||||
1. The `dateFormat` parameter passed to the "now" shortcode, if present
|
||||
2. The `dateFormat` parameter passed to the "greeting" shortcode, if present
|
||||
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
|
||||
|
|
|
@ -11,21 +11,21 @@ action:
|
|||
signatures: [SHORTCODE.Position]
|
||||
---
|
||||
|
||||
The `Position` method is useful for error reporting. For example, if your shortcode requires a "greeting" parameter:
|
||||
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' parameter. See %s" .Name .Position }}
|
||||
{{ errorf "The %q shortcode requires a 'greeting' argument. See %s" .Name .Position }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
In the absence of a "greeting" parameter, Hugo will throw an error message and fail the build:
|
||||
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' parameter. See "/home/user/project/content/about.md:11:1"
|
||||
ERROR The "myshortcode" shortcode requires a 'greeting' argument. See "/home/user/project/content/about.md:11:1"
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
title: Scratch
|
||||
description: Creates a "scratch pad" scoped to the shortcode to store and manipulate data.
|
||||
description: Returns a "scratch pad" scoped to the shortcode to store and manipulate data.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
|
@ -16,7 +16,7 @@ The `Scratch` method within a shortcode creates a [scratch pad] to store and man
|
|||
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
|
||||
[`newScratch`]: /functions/collections/newscratch/
|
||||
{{% /note %}}
|
||||
|
||||
[scratch pad]: /getting-started/glossary/#scratch-pad
|
||||
|
|
|
@ -12,7 +12,7 @@ action:
|
|||
|
||||
See [Site methods].
|
||||
|
||||
[Site methods]: /methods/site
|
||||
[Site methods]: /methods/site/
|
||||
|
||||
```go-html-template
|
||||
{{ .Site.Title }}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue