60dd993a6content: Update GitHub Pages workflow6247e3590content: Fix typoa22255b0bcontent: Update version references21afec198content: Update version reference6226532c8content: Update version reference80d26621acontent: Update version referencecda7135b5content: Fix typo70c509e8acontent: Fix typo136b20310content: Change render hook example038246c2fcontent: Fix accidental removal441375fa4netlify: Hugo 0.147.94a620931ccontent: Note that config/env/cascade.xxx is not supported6d3a7587fconfig: Ignore front matter param override warnings623b48624content: Set searchable param to false for content/en/documentation.mdd1b2aad69content: Fix Codeberg deployment article5e3d849b8search: Use front matter parameter to control search indexingb4f90e39dcontent: Note that PATH segments must exclude project directorya81406e26content: Create aliases for deleted template pages7c3adc9adcontent: Change order of template typese093eb036content: Remove admonition from template types page0015e7a9bcontent: Update to align with v0.146.0 template system (phase 1)cf986240dcontent: Update templates.Defer noteab51fdcc7content: Use consistent templates.Defer examplesb4f8e492fcontent: Fix formatting62aa94addcontent: Fix typo83747f36bcontent: Update FAQsfc644d894Update netlify.toml4151f3a5bcontent: Fix typo9452bca92content: Update description ToMath strict option982b863c3content: Add instructions about deploying to root of user's Codeberg Pagesfc7cd2878theme: Generate QR code once per page784891b87content: Update links to the CommonMark specification741113fb5content: Fix incorrect link to Shortcodes tutorialc4962f1accontent: Update transform.ToMathad7b87223Update netlify.toml2d64e57aetheme: Remove bullet from new-in badge55a832f8eUpdate ToMath.mde1e624f49content: Document transform.ToMath strict mode2df6218f8netlify: Hugo 0.147.60259b88f1Revert "theme: Display date on news items from content adapter"43b35e56atheme: Adjust admonition dark mode colors2f15e9c34theme: Add link to Mastodond99e979d4theme: Display date on news items from content adapter6c93dac97content: Clarify the AddResource content value49006468econtent: Describe Codeberg's Forgejo Actionsbe80c3b82content: Update css.TailwindCSS optsb3ba4329ctheme: Update css.TailwindCSS opts and remove tailwind.config.js902e360b0content: Update stylesheet link for katex.js8b9e1ba3econtent: Update stylesheet link for katex.js7dae3b0e8content: Update TailwindCSS instructionscb093d210Update netlify.toml577d6fbb1content: Remove GitCMS for now8352af6cdUpdates for v0.147.42240f07a5content: Fix typo677b3fed3Correct openapi3.Unmarshal example580477aa5content: Fix typo0dc43b481content: Add GitCMS to commercial front ends listac4179f2bcontent: Fix relref shortcode examplesa699d267bFix typos7e28c4380Make sponsor logo responsive8e05f0425Update MaxInt64.mdf715265d3content: Document math.MaxInt640d57ff7d4Update netlify.tomld210e3476theme: Adjust sponsore73444b43content: Clarify page title valuesfd4c292b8content: Fix links to Pandocdd074dc67content: Bump version in GitHub Pages examplefe5537bb2content: Describe the pandoc format10834529etheme: Remove duplicate meta element838706d6etheme: More changes related to new template systemb0b6b1e69Update new-templatesystem-overview.mde719d2360Update new-templatesystem-overview.mdec2bbd395Update new-templatesystem-overview.md53319a681Add a one pager about the new template systeme17416c05Fix the spelling issue on the Host on Render descriptione8e1c82aacontent: Document range-over-int introduced in v0.123.0bc478f98fcontent: Fix editing errors606547b48Update netlify.tomle224f3f82content: Fix formatting24e4acc41content: Fix typo1e773f34bcontent: Fix typo5ef94a725content: Document alternative to shuffle for large collections7fe42d76ccontent: Fix sample code formatting5d601448fcontent: Update mathematical markup guidance63b4fe2c0content: Update version references722da91f1content: Fix GO_VERSION in Netlify hosting example8cc589c3atheme: Add current Hugo version to the header37aa24ac5netlify: Hugo 0.147.1a80b25e24content: Remove dated new-in89dcf0f92content: Fix path formatting1a5191d78content: Update transformation examples3327065abUpdate Text.md557c10dd2content: Miscellaneous updates for v0.147.00dae1a185netlify: Hugo 0.147.09b44821c3Merge branch 'tempv0.147.0'f1481e8c3content: Update GitLab Pages workflow example2e61a0360content: Update content format descriptionsfb42d7c2aimages: Add option for vertical alignment to images.Text git-subtree-dir: docs git-subtree-split:60dd993a65
4.3 KiB
title, description, categories, keywords, params
| title | description | categories | keywords | params | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Inner | Returns the content between opening and closing shortcode tags, applicable when the shortcode call includes a closing tag. |
|
This content:
{{</* card title="Product Design" */>}}
We design the **best** widgets in the world.
{{</* /card */>}}
With this shortcode:
<div class="card">
{{ with .Get "title" }}
<div class="card-title">{{ . }}</div>
{{ end }}
<div class="card-content">
{{ .Inner | strings.TrimSpace }}
</div>
</div>
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.TrimSpacefunction as shown above to remove carriage returns and newlines.
Note
In the example above, the value returned by
Inneris Markdown, but it was rendered as plain text. Use either of the following approaches to render Markdown to HTML.
Use RenderString
Let's modify the example above to pass the value returned by Inner through the RenderString method on the Page object:
<div class="card">
{{ with .Get "title" }}
<div class="card-title">{{ . }}</div>
{{ end }}
<div class="card-content">
{{ .Inner | strings.TrimSpace | .Page.RenderString }}
</div>
</div>
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.
Alternative notation
Instead of calling the shortcode with the {{</* */>}} notation, use the {{%/* */%}} notation:
{{%/* card title="Product Design" */%}}
We design the **best** widgets in the world.
{{%/* /card */%}}
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.
<div class="card">
{{ with .Get "title" }}
<div class="card-title">{{ . }}</div>
{{ end }}
<div class="card-content">
{{ .Inner | strings.TrimSpace }}
</div>
</div>
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
Don't process the
Innervalue withRenderStringormarkdownifywhen using Markdown notation to call the shortcode.