159c843fdFix front matter menu entry examplec3a476a19Document soft deprecation of PAGE.Scratchcdead9785netlify: Hugo 0.138.09169b4da4Update version references3bc6bf431Update embedded.md5c7743b2eUpdate creation instructions for the emoji quick reference109efe3ebDocument the comment shortcode83d7d3005Update themed3c205054netlify: Hugo 0.137.1545290351Handle inline HTML content0204be97dUpdate theme18d09235eRemove JS and CSS that prevents FOUC with client side math rendering63d9dd876Update RenderShortcodes.md064b95539Update output-format-definition.md3744f3be2Describe and refer to the extended/deploy edition3d3302308netlify: Hugo 0.137.0b53aedceaUpdate RenderShortcodes.mdb5f289165Replace HTML comments in markdown with the new comment shortcodec673880b6Remove superfluous right bracketf80b0c61eUpdate faq.md2ede707ebDocument installation on NixOS09b114914Update theme76a9f90b2Update passthrough.md9f3355630Update Scratch.mdbc080ecaaUpdate Store.md1507ede32Update Scratch.md54a90f569Update Store.md7c9145c43Fix broken linkdd15f183bUpdate ToMath.md2b021c34bMove the [build] documentation to its own pagecbb6677ecFix typoac0969063Update ToMath.md7fbdfd7c8netlify: Hugo 0.136.517f54223cUpdate ToMath.md4c9c3bb06Update multilingual.md1432da7bdMake site and page language methods linkablefd5b746cbUpdate urls.mda746f1b3aUpdate urls.mdabf8738e2netlify: Hugo 0.136.4bd8759996Update TrimSpace.md6103c1e84Documents strings.TrimSpace533dd3a7bnetlify: Hugo 0.136.330f3f97cfUpdate quick-start.mdb0d7b41a0Update configuration-markup.md760e5e4f0Update quick-start.md17daeb866Update quick-start.md1e158e723netlify: Hugo 0.136.2d32530839Update themeedb9bee02Update description of url front matter fielde1c576e18netlify: Hugo 0.136.11ad28e1e0Describe how to configure uglyURLs per sectioncbbd4c4fenetlify: Hugo 0.136.0bb7f35e99Merge branch 'tempv0.136.0'706110736docs: Regen CLI docsbf0c7821fUpdate urls.md8c544e6c0Update quick-start.md8d02733d0Update Paginator.mda45327aacUpdate Paginate.md1377ed4deClarify date parsinge19fb8043Document front matter date field aliasesa39951847Update Tailwind CSS installation instructions3be164c35Remove duplicate token05fc815f7commands: Add "hugo build" as an alias for "hugo"cb3cb504cUpdate table render hook exampleefbee0bffClarify resources.GetRemote 404 handling4312d49c9Update compare.Conditional documentation4a46d53b6Update theme93e542d4fnetlify: Hugo 0.135.0b4da1c104Remvoe some old new-in shortcodes4c316f051Update TailwindCSS.mdc2fe91509Update introduction.md906b7c66bUpdate configuration.md5ab6b3cddUpdate documentation.md26fb4bb4cUpdate documentation.mde9e917f37Update version refs83ce07f24netlify: Hugo 0.134.38cb32f802Update front-matter.md94d7f576aUpdate faq.mdfafc1d8d9netlify: Hugo 0.134.2bfe9cdc3dUpdate content-adapters.md9e49ae3e1Document ignoreLogs configuration setting6b47a1d57Update configuration.mdfd98a0372Document CLI options that can be set in configuration07c2400d8Document alternative to Summary methodd053fa163Update to reflect changes in v0.134.1137dc3241Update ContentWithoutSummary.mde8f6427d9netlify: Hugo 0.134.1 git-subtree-dir: docs git-subtree-split:159c843fd7
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. |
|
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 >}}
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 >}}
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 >}}
{{ .Inner | strings.TrimSpace }}
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 %}}