Files
hugo/content/en/methods/shortcode/Inner.md
T
Bjørn Erik Pedersen de0df119b5 Squashed 'docs/' changes from ccb1b97cb..159c843fd
159c843fd Fix front matter menu entry example
c3a476a19 Document soft deprecation of PAGE.Scratch
cdead9785 netlify: Hugo 0.138.0
9169b4da4 Update version references
3bc6bf431 Update embedded.md
5c7743b2e Update creation instructions for the emoji quick reference
109efe3eb Document the comment shortcode
83d7d3005 Update theme
d3c205054 netlify: Hugo 0.137.1
545290351 Handle inline HTML content
0204be97d Update theme
18d09235e Remove JS and CSS that prevents FOUC with client side math rendering
63d9dd876 Update RenderShortcodes.md
064b95539 Update output-format-definition.md
3744f3be2 Describe and refer to the extended/deploy edition
3d3302308 netlify: Hugo 0.137.0
b53aedcea Update RenderShortcodes.md
b5f289165 Replace HTML comments in markdown with the new comment shortcode
c673880b6 Remove superfluous right bracket
f80b0c61e Update faq.md
2ede707eb Document installation on NixOS
09b114914 Update theme
76a9f90b2 Update passthrough.md
9f3355630 Update Scratch.md
bc080ecaa Update Store.md
1507ede32 Update Scratch.md
54a90f569 Update Store.md
7c9145c43 Fix broken link
dd15f183b Update ToMath.md
2b021c34b Move the [build] documentation to its own page
cbb6677ec Fix typo
ac0969063 Update ToMath.md
7fbdfd7c8 netlify: Hugo 0.136.5
17f54223c Update ToMath.md
4c9c3bb06 Update multilingual.md
1432da7bd Make site and page language methods linkable
fd5b746cb Update urls.md
a746f1b3a Update urls.md
abf8738e2 netlify: Hugo 0.136.4
bd8759996 Update TrimSpace.md
6103c1e84 Documents strings.TrimSpace
533dd3a7b netlify: Hugo 0.136.3
30f3f97cf Update quick-start.md
b0d7b41a0 Update configuration-markup.md
760e5e4f0 Update quick-start.md
17daeb866 Update quick-start.md
1e158e723 netlify: Hugo 0.136.2
d32530839 Update theme
edb9bee02 Update description of url front matter field
e1c576e18 netlify: Hugo 0.136.1
1ad28e1e0 Describe how to configure uglyURLs per section
cbbd4c4fe netlify: Hugo 0.136.0
bb7f35e99 Merge branch 'tempv0.136.0'
706110736 docs: Regen CLI docs
bf0c7821f Update urls.md
8c544e6c0 Update quick-start.md
8d02733d0 Update Paginator.md
a45327aac Update Paginate.md
1377ed4de Clarify date parsing
e19fb8043 Document front matter date field aliases
a39951847 Update Tailwind CSS installation instructions
3be164c35 Remove duplicate token
05fc815f7 commands: Add "hugo build" as an alias for "hugo"
cb3cb504c Update table render hook example
efbee0bff Clarify resources.GetRemote 404 handling
4312d49c9 Update compare.Conditional documentation
4a46d53b6 Update theme
93e542d4f netlify: Hugo 0.135.0
b4da1c104 Remvoe some old new-in shortcodes
4c316f051 Update TailwindCSS.md
c2fe91509 Update introduction.md
906b7c66b Update configuration.md
5ab6b3cdd Update documentation.md
26fb4bb4c Update documentation.md
e9e917f37 Update version refs
83ce07f24 netlify: Hugo 0.134.3
8cb32f802 Update front-matter.md
94d7f576a Update faq.md
fafc1d8d9 netlify: Hugo 0.134.2
bfe9cdc3d Update content-adapters.md
9e49ae3e1 Document ignoreLogs configuration setting
6b47a1d57 Update configuration.md
fd98a0372 Document CLI options that can be set in configuration
07c2400d8 Document alternative to Summary method
d053fa163 Update to reflect changes in v0.134.1
137dc3241 Update ContentWithoutSummary.md
e8f6427d9 netlify: Hugo 0.134.1

git-subtree-dir: docs
git-subtree-split: 159c843fd7
2024-11-13 11:07:57 +01:00

4.4 KiB

title, description, categories, keywords, action
title description categories keywords action
Inner Returns the content between opening and closing shortcode tags, applicable when the shortcode call includes a closing tag.
related returnType signatures
functions/strings/Trim
methods/page/RenderString
functions/transform/Markdownify
methods/shortcode/InnerDeindent
template.HTML
SHORTCODE.Inner

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 >}}

{{ with .Get "title" }}
{{ . }}
{{ end }}
{{ .Inner | strings.TrimSpace }}
{{< /code >}}

Is rendered to:

<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.

{{% /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 the RenderString method

Let's modify the example above to pass the value returned by Inner through the RenderString method on the Page object:

{{< code file=layouts/shortcodes/card.html >}}

{{ with .Get "title" }}
{{ . }}
{{ end }}
{{ .Inner | strings.TrimSpace | .Page.RenderString }}
{{< /code >}}

Hugo renders this to:

<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.

Use alternate 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 >}}

{{ with .Get "title" }}
{{ . }}
{{ end }}

{{ .Inner | strings.TrimSpace }}

{{< /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.

--- 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 %}}