f0f4bcb24Update Batch.md15a8b1de6Update Batch.mdeb841ce66Update theme751097f24Use CI_PAGES_URL in GitLab Pages workflow8584a0581Fix typosb030a7149Update configuration.mdf7ec2ee9cRevert "Update shortcode.md"f8188f1c8Update shortcode.md083fc39c6Update shortcode.mdd4bdfb96bUpdate Filter.mdef00649dbDocument wrapperClass highlighting optione227dc422Hugo 0.140.2b95d28444Fix description of the the hugo server command41ca381b0Fix documentation of Fragments73a6cd966Update theme2573fd120netlify: Hugo 0.140.190b19ec0dMerge branch 'tempv0.140.1'ad2e9aeecUpdate gocloud and docs for S3-Compatible Endpoints34b30bad2Remove indentation from include shortcode examples97b4ef544Update related.md7234e0189Update related.md32cc191f6Clarify Name and Title menu entry methodsbce733c63Update theme2f1843d10Use .Page.GetPage in examples of an include shortcode9e1c85bbdRevert "Document PAGE.String"bb30e7c08Document PAGE.String2d151d77fFix linkfbe2d442fMiscellaneous updates for v0.140.04d3195223Update JS docs vs Hugo v0.1408c190aabcnetlify: Hugo 0.140.0826005ffeMerge branch 'tempv0.140.0'107289a2cUpdate theme (again)9884425f9Update themeff0a358d3Update Go tool version in hugo.workc9b23cf6dtpl/tplimpl: Update details shortcodef29f19afftpl/tplimpl: Add details shortcode git-subtree-dir: docs git-subtree-split:f0f4bcb243
2.8 KiB
title, description, categories, keywords, action, toc
| title | description | categories | keywords | action | toc | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| RenderShortcodes | Renders all shortcodes in the content of the given page, preserving the surrounding markup. |
|
true |
{{< new-in 0.117.0 >}}
Use this method in shortcode templates to compose a page from multiple content files, while preserving a global context for footnotes and the table of contents.
For example:
{{< code file=layouts/shortcodes/include.html >}}
{{ with .Get 0 }}
{{ with $.Page.GetPage . }}
{{- .RenderShortcodes }}
{{ else }}
{{ errorf "The %q shortcode was unable to find %q. See %s" .Name . .Position }}
{{ end }}
{{ else }}
{{ errorf "The %q shortcode requires a positional parameter indicating the logical path of the file to include. See %s" .Name .Position }}
{{ end }}
{{< /code >}}
Then call the shortcode in your Markdown:
{{< code file=content/about.md lang=md >}} {{%/* include "/snippets/services" /%}} {{%/ include "/snippets/values" /%}} {{%/ include "/snippets/leadership" */%}} {{< /code >}}
Each of the included Markdown files can contain calls to other shortcodes.
Shortcode notation
In the example above it's important to understand the difference between the two delimiters used when calling a shortcode:
{{</* myshortcode */>}}tells Hugo that the rendered shortcode does not need further processing. For example, the shortcode content is HTML.{{%/* myshortcode */%}}tells Hugo that the rendered shortcode needs further processing. For example, the shortcode content is Markdown.
Use the latter for the "include" shortcode described above.
Further explanation
To understand what is returned by the RenderShortcodes method, consider this content file
{{< code file=content/about.md lang=text >}} +++ title = 'About' date = 2023-10-07T12:28:33-07:00 +++
{{</* ref "privacy" */>}}
An emphasized word. {{< /code >}}
With this template code:
{{ $p := site.GetPage "/about" }}
{{ $p.RenderShortcodes }}
Hugo renders this:;
https://example.org/privacy/
An *emphasized* word.
Note that the shortcode within the content file was rendered, but the surrounding Markdown was preserved.
Limitations
The primary use case for .RenderShortcodes is inclusion of Markdown content. If you try to use .RenderShortcodes inside HTML blocks when inside Markdown, you will get a warning similar to this:
WARN .RenderShortcodes detected inside HTML block in "/content/mypost.md"; this may not be what you intended ...
The above warning can be turned off is this is what you really want.