mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-24 15:28:54 +00:00
Remove superfluous shortcode param
This commit is contained in:
@@ -49,7 +49,7 @@ In addition to using a single site configuration file, one can use the `configDi
|
||||
foo = "bar"
|
||||
{{< /code-toggle >}}
|
||||
|
||||
{{< code-toggle file="params" copy=false >}}
|
||||
{{< code-toggle file="params" >}}
|
||||
foo = "bar"
|
||||
{{< /code-toggle >}}
|
||||
|
||||
@@ -78,7 +78,7 @@ Let's take an example to understand this better. Let's say you are using Google
|
||||
|
||||
[Google tag ID]: https://support.google.com/tagmanager/answer/12326985?hl=en
|
||||
|
||||
{{< code-toggle file=hugo copy=false >}}
|
||||
{{< code-toggle file=hugo >}}
|
||||
[services.googleAnalytics]
|
||||
ID = 'G-XXXXXXXXX'
|
||||
{{< /code-toggle >}}
|
||||
@@ -103,7 +103,7 @@ To satisfy these requirements, configure your site as follows:
|
||||
|
||||
Include this section only:
|
||||
|
||||
{{< code-toggle file=hugo copy=false >}}
|
||||
{{< code-toggle file=hugo >}}
|
||||
[services.googleAnalytics]
|
||||
ID = 'G-PPPPPPPPP'
|
||||
{{< /code-toggle >}}
|
||||
@@ -116,7 +116,7 @@ To satisfy these requirements, configure your site as follows:
|
||||
|
||||
Include this section only:
|
||||
|
||||
{{< code-toggle file=hugo copy=false >}}
|
||||
{{< code-toggle file=hugo >}}
|
||||
[services.googleAnalytics]
|
||||
ID = 'G-SSSSSSSSS'
|
||||
{{< /code-toggle >}}
|
||||
|
||||
@@ -14,7 +14,7 @@ Use the `Children` method when rendering a nested menu.
|
||||
|
||||
With this site configuration:
|
||||
|
||||
{{< code-toggle file=hugo copy=false >}}
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
name = 'Products'
|
||||
pageRef = '/product'
|
||||
|
||||
@@ -14,7 +14,7 @@ Use the `HasChildren` method when rendering a nested menu.
|
||||
|
||||
With this site configuration:
|
||||
|
||||
{{< code-toggle file=hugo copy=false >}}
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
name = 'Products'
|
||||
pageRef = '/product'
|
||||
|
||||
@@ -13,7 +13,7 @@ The `Identifier` method returns the `identifier` property of the menu entry. If
|
||||
|
||||
[automatically]: /content-management/menus/#define-automatically
|
||||
|
||||
{{< code-toggle file=hugo copy=false >}}
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
identifier = 'about'
|
||||
name = 'About'
|
||||
|
||||
@@ -11,7 +11,7 @@ action:
|
||||
|
||||
In this menu definition, the second entry does not contain an `identifier`, so the `Identifier` method returns its `name` property instead:
|
||||
|
||||
{{< code-toggle file=hugo copy=false >}}
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
identifier = 'about'
|
||||
name = 'About'
|
||||
|
||||
@@ -13,7 +13,7 @@ Regardless of how you [define menu entries], an entry associated with a page has
|
||||
|
||||
In this menu definition, the first two entries are associated with a page, the last entry is not:
|
||||
|
||||
{{< code-toggle file=hugo copy=false >}}
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
pageRef = '/about'
|
||||
weight = 10
|
||||
|
||||
@@ -11,7 +11,7 @@ action:
|
||||
|
||||
When you define menu entries [in site configuration] or [in front matter], you can include a `params` key to attach additional information to the entry. For example:
|
||||
|
||||
{{< code-toggle file=hugo copy=false >}}
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
name = 'About'
|
||||
pageRef = '/about'
|
||||
|
||||
@@ -11,7 +11,7 @@ action:
|
||||
|
||||
With this menu definition:
|
||||
|
||||
{{< code-toggle file=hugo copy=false >}}
|
||||
{{< code-toggle file=hugo >}}
|
||||
[menu]
|
||||
[[menu.main]]
|
||||
name = 'Products'
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
In this site configuration we enable rendering of [emoji shortcodes], and add emoji shortcodes before (pre) and after (post) each menu entry:
|
||||
|
||||
{{< code-toggle file=hugo copy=false >}}
|
||||
{{< code-toggle file=hugo >}}
|
||||
enableEmoji = true
|
||||
|
||||
[[menu.main]]
|
||||
|
||||
@@ -13,7 +13,7 @@ The `Sort` method returns the given menu with its entries sorted by `name`.
|
||||
|
||||
Consider this menu definition:
|
||||
|
||||
{{< code-toggle file=hugo copy=false >}}
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
name = 'Services'
|
||||
pageRef = '/services'
|
||||
|
||||
@@ -15,7 +15,7 @@ The `ByWeight` method returns the given menu with its entries sorted by [`weight
|
||||
|
||||
Consider this menu definition:
|
||||
|
||||
{{< code-toggle file=hugo copy=false >}}
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
identifier = 'about'
|
||||
name = 'About'
|
||||
|
||||
@@ -13,7 +13,7 @@ The `Limit` method returns the given menu, limited to the first N entries.
|
||||
|
||||
Consider this menu definition:
|
||||
|
||||
{{< code-toggle file=hugo copy=false >}}
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
name = 'Services'
|
||||
pageRef = '/services'
|
||||
|
||||
@@ -13,7 +13,7 @@ The `Reverse` method returns the given menu, reversing the sort order of its ent
|
||||
|
||||
Consider this menu definition:
|
||||
|
||||
{{< code-toggle file=hugo copy=false >}}
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[menu.main]]
|
||||
name = 'Services'
|
||||
pageRef = '/services'
|
||||
|
||||
@@ -15,7 +15,7 @@ Based on front matter, Hugo uses several factors to identify content related to
|
||||
|
||||
The argument passed to the `Related` method may be a `Page` or an options map. For example, to pass the current page:
|
||||
|
||||
{{< code file="layouts/_default/single.html" lang=go-html-template copy=false >}}
|
||||
{{< code file="layouts/_default/single.html" lang=go-html-template >}}
|
||||
{{ with .Site.RegularPages.Related . | first 5 }}
|
||||
<p>Related pages:</p>
|
||||
<ul>
|
||||
@@ -28,7 +28,7 @@ The argument passed to the `Related` method may be a `Page` or an options map. F
|
||||
|
||||
To pass an options map:
|
||||
|
||||
{{< code file="layouts/_default/single.html" lang=go-html-template copy=false >}}
|
||||
{{< code file="layouts/_default/single.html" lang=go-html-template >}}
|
||||
{{ $opts := dict
|
||||
"document" .
|
||||
"indices" (slice "tags" "keywords")
|
||||
|
||||
@@ -14,7 +14,7 @@ action:
|
||||
|
||||
By way of example, consider this site configuration:
|
||||
|
||||
{{< code-toggle file=hugo copy=false >}}
|
||||
{{< code-toggle file=hugo >}}
|
||||
baseURL = 'https://example.org/docs/'
|
||||
{{< /code-toggle >}}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ content/
|
||||
|
||||
And this front matter:
|
||||
|
||||
{{< code-toggle file=content/posts/cats.md fm=true copy=false >}}
|
||||
{{< code-toggle file=content/posts/cats.md fm=true >}}
|
||||
title = 'Cats'
|
||||
[[resources]]
|
||||
src = 'images/a.jpg'
|
||||
|
||||
@@ -34,7 +34,7 @@ content/
|
||||
|
||||
With the structure above, we can range through page resources of type `page` to build content:
|
||||
|
||||
{{< code file="layouts/lessons/single.html" lang=go-html-template copy=false >}}
|
||||
{{< code file="layouts/lessons/single.html" lang=go-html-template >}}
|
||||
{{ range .Resources.ByType "page" }}
|
||||
{{ .Content }}
|
||||
{{ end }}
|
||||
|
||||
@@ -22,13 +22,13 @@ Some shortcodes support positional parameters, some support named parameters, an
|
||||
|
||||
This shortcode call uses positional parameters:
|
||||
|
||||
{{< code file="content/about.md" lang=md copy=false >}}
|
||||
{{< code file="content/about.md" lang=md >}}
|
||||
{{</* myshortcode "Hello" "world" */>}}
|
||||
{{< /code >}}
|
||||
|
||||
To retrieve parameters by position:
|
||||
|
||||
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template copy=false >}}
|
||||
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template >}}
|
||||
{{ printf "%s %s." (.Get 0) (.Get 1) }} → Hello world.
|
||||
{{< /code >}}
|
||||
|
||||
@@ -36,13 +36,13 @@ To retrieve parameters by position:
|
||||
|
||||
This shortcode call uses named parameters:
|
||||
|
||||
{{< code file="content/about.md" lang=md copy=false >}}
|
||||
{{< code file="content/about.md" lang=md >}}
|
||||
{{</* myshortcode greeting="Hello" firstName="world" */>}}
|
||||
{{< /code >}}
|
||||
|
||||
To retrieve parameters by name:
|
||||
|
||||
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template copy=false >}}
|
||||
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template >}}
|
||||
{{ printf "%s %s." (.Get "greeting") (.Get "firstName") }} → Hello world.
|
||||
{{< /code >}}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ action:
|
||||
|
||||
This content:
|
||||
|
||||
{{< code file="content/services.md" lang=md copy=false >}}
|
||||
{{< code file="content/services.md" lang=md >}}
|
||||
{{</* card title="Product Design" */>}}
|
||||
We design the **best** widgets in the world.
|
||||
{{</* /card */>}}
|
||||
@@ -23,7 +23,7 @@ We design the **best** widgets in the world.
|
||||
|
||||
With this shortcode:
|
||||
|
||||
{{< code file="layouts/shortcodes/card.html" lang=go-html-template copy=false >}}
|
||||
{{< code file="layouts/shortcodes/card.html" lang=go-html-template >}}
|
||||
<div class="card">
|
||||
{{ with .Get "title" }}
|
||||
<div class="card-title">{{ . }}</div>
|
||||
@@ -62,7 +62,7 @@ Let's modify the example above to pass the value returned by `Inner` through the
|
||||
|
||||
[`RenderString`]: /methods/page/renderstring
|
||||
|
||||
{{< code file="layouts/shortcodes/card.html" lang=go-html-template copy=false >}}
|
||||
{{< code file="layouts/shortcodes/card.html" lang=go-html-template >}}
|
||||
<div class="card">
|
||||
{{ with .Get "title" }}
|
||||
<div class="card-title">{{ . }}</div>
|
||||
@@ -93,7 +93,7 @@ You can use the [`markdownify`] function instead of the `RenderString` method, b
|
||||
|
||||
Instead of calling the shortcode with the `{{</* */>}}` notation, use the `{{%/* */%}}` notation:
|
||||
|
||||
{{< code file="content/services.md" lang=md copy=false >}}
|
||||
{{< code file="content/services.md" lang=md >}}
|
||||
{{%/* card title="Product Design" */%}}
|
||||
We design the **best** widgets in the world.
|
||||
{{%/* /card */%}}
|
||||
@@ -103,7 +103,7 @@ When you use the `{{%/* */%}}` notation, Hugo renders the entire shortcode as ma
|
||||
|
||||
First, configure the renderer to allow raw HTML within markdown:
|
||||
|
||||
{{< code-toggle file=hugo copy=false >}}
|
||||
{{< code-toggle file=hugo >}}
|
||||
[markup.goldmark.renderer]
|
||||
unsafe = true
|
||||
{{< /code-toggle >}}
|
||||
@@ -112,7 +112,7 @@ This configuration is not unsafe if _you_ control the content. Read more about H
|
||||
|
||||
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" lang=go-html-template copy=false >}}
|
||||
{{< code file="layouts/shortcodes/card.html" lang=go-html-template >}}
|
||||
<div class="card">
|
||||
{{ with .Get "title" }}
|
||||
<div class="card-title">{{ . }}</div>
|
||||
|
||||
@@ -16,7 +16,7 @@ This allows us to effectively bypass the rules governing [indentation] as provid
|
||||
|
||||
Consider this markdown, an unordered list with a small gallery of thumbnail images within each list item:
|
||||
|
||||
{{< code file="content/about.md" lang=md copy=false >}}
|
||||
{{< code file="content/about.md" lang=md >}}
|
||||
- Gallery one
|
||||
|
||||
{{</* gallery */>}}
|
||||
@@ -36,7 +36,7 @@ In the example above, notice that the content between the opening and closing sh
|
||||
|
||||
With this shortcode, calling `Inner` instead of `InnerDeindent`:
|
||||
|
||||
{{< code file="layouts/shortcodes/gallery.html" lang=go-html-template copy=false >}}
|
||||
{{< code file="layouts/shortcodes/gallery.html" lang=go-html-template >}}
|
||||
<div class="gallery">
|
||||
{{ trim .Inner "\r\n" | .Page.RenderString }}
|
||||
</div>
|
||||
@@ -67,7 +67,7 @@ Hugo renders the markdown to:
|
||||
|
||||
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" lang=go-html-template copy=false >}}
|
||||
{{< code file="layouts/shortcodes/gallery.html" lang=go-html-template >}}
|
||||
<div class="gallery">
|
||||
{{ trim .InnerDeindent "\r\n" | .Page.RenderString }}
|
||||
</div>
|
||||
|
||||
@@ -14,7 +14,7 @@ To support both positional and named parameters when calling a shortcode, use th
|
||||
|
||||
With this shortcode template:
|
||||
|
||||
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template copy=false >}}
|
||||
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template >}}
|
||||
{{ if .IsNamedParams }}
|
||||
{{ printf "%s %s." (.Get "greeting") (.Get "firstName") }}
|
||||
{{ else }}
|
||||
@@ -24,7 +24,7 @@ With this shortcode template:
|
||||
|
||||
Both of these calls return the same value:
|
||||
|
||||
{{< code file="content/about.md" lang=md copy=false >}}
|
||||
{{< code file="content/about.md" lang=md >}}
|
||||
{{</* myshortcode greeting="Hello" firstName="world" */>}}
|
||||
{{</* myshortcode "Hello" "world" */>}}
|
||||
{{< /code >}}
|
||||
|
||||
@@ -13,7 +13,7 @@ action:
|
||||
|
||||
The `Name` method is useful for error reporting. For example, if your shortcode requires a "greeting" parameter:
|
||||
|
||||
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template copy=false >}}
|
||||
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template >}}
|
||||
{{ $greeting := "" }}
|
||||
{{ with .Get "greeting" }}
|
||||
{{ $greeting = . }}
|
||||
|
||||
@@ -13,7 +13,7 @@ The `Ordinal` method returns the zero-based ordinal of the shortcode in relation
|
||||
|
||||
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 copy=false >}}
|
||||
{{< code file="content/about.md" lang=md >}}
|
||||
{{</* img src="images/a.jpg" */>}}
|
||||
|
||||
{{</* img src="images/b.jpg" */>}}
|
||||
@@ -21,7 +21,7 @@ This method is useful for, among other things, assigning unique element IDs when
|
||||
|
||||
This shortcode performs error checking, then renders an HTML `img` element with a unique `id` attribute:
|
||||
|
||||
{{< code file="layouts/shortcodes/img.html" lang=go-html-template copy=false >}}
|
||||
{{< code file="layouts/shortcodes/img.html" lang=go-html-template >}}
|
||||
{{ $src := "" }}
|
||||
{{ with .Get "src" }}
|
||||
{{ $src = . }}
|
||||
|
||||
@@ -11,7 +11,7 @@ action:
|
||||
|
||||
With this content:
|
||||
|
||||
{{< code-toggle file=content/books/les-miserables.md copy=false fm=true >}}
|
||||
{{< code-toggle file=content/books/les-miserables.md fm=true >}}
|
||||
title = 'Les Misérables'
|
||||
author = 'Victor Hugo'
|
||||
published = 1862
|
||||
@@ -26,7 +26,7 @@ Calling this shortcode:
|
||||
|
||||
We can access the front matter values using the `Page` method:
|
||||
|
||||
{{< code file="layouts/shortcodes/book-details.html" lang=go-html-template copy=false >}}
|
||||
{{< code file="layouts/shortcodes/book-details.html" lang=go-html-template >}}
|
||||
<ul>
|
||||
<li>Title: {{ .Page.Title }}</li>
|
||||
<li>Author: {{ .Page.Params.author }}</li>
|
||||
|
||||
@@ -12,22 +12,22 @@ action:
|
||||
|
||||
When you call a shortcode using positional parameters, the `Params` method returns a slice.
|
||||
|
||||
{{< code file="content/about.md" lang=md copy=false >}}
|
||||
{{< code file="content/about.md" lang=md >}}
|
||||
{{</* myshortcode "Hello" "world" */>}}
|
||||
{{< /code >}}
|
||||
|
||||
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template copy=false >}}
|
||||
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template >}}
|
||||
{{ index .Params 0 }} → Hello
|
||||
{{ index .Params 1 }} → world
|
||||
{{< /code >}}
|
||||
|
||||
When you call a shortcode using named parameters, the `Params` method returns a map.
|
||||
|
||||
{{< code file="content/about.md" lang=md copy=false >}}
|
||||
{{< code file="content/about.md" lang=md >}}
|
||||
{{</* myshortcode greeting="Hello" name="world" */>}}
|
||||
{{< /code >}}
|
||||
|
||||
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template copy=false >}}
|
||||
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template >}}
|
||||
{{ .Params.greeting }} → Hello
|
||||
{{ .Params.name }} → world
|
||||
{{< /code >}}
|
||||
|
||||
@@ -13,19 +13,19 @@ This is useful for inheritance of common shortcode parameters 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 copy=false >}}
|
||||
{{< code file="content/welcome.md" lang=md >}}
|
||||
{{</* greeting dateFormat="Jan 2, 2006" */>}}
|
||||
Welcome. Today is {{</* now */>}}.
|
||||
{{</* /greeting */>}}
|
||||
{{< /code >}}
|
||||
|
||||
{{< code file="layouts/shortcodes/greeting.html" lang=go-html-template copy=false >}}
|
||||
{{< code file="layouts/shortcodes/greeting.html" lang=go-html-template >}}
|
||||
<div class="greeting">
|
||||
{{ trim .Inner "\r\n" | .Page.RenderString }}
|
||||
</div>
|
||||
{{< /code >}}
|
||||
|
||||
{{< code file="layouts/shortcodes/now.html" lang=go-html-template copy=false >}}
|
||||
{{< code file="layouts/shortcodes/now.html" lang=go-html-template >}}
|
||||
{{- $dateFormat := "January 2, 2006 15:04:05" }}
|
||||
|
||||
{{- with .Params }}
|
||||
|
||||
@@ -13,7 +13,7 @@ action:
|
||||
|
||||
The `Position` method is useful for error reporting. For example, if your shortcode requires a "greeting" parameter:
|
||||
|
||||
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template copy=false >}}
|
||||
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template >}}
|
||||
{{ $greeting := "" }}
|
||||
{{ with .Get "greeting" }}
|
||||
{{ $greeting = . }}
|
||||
|
||||
Reference in New Issue
Block a user