mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-22 21:42:50 +02:00
Merge commit '5be51ac3db225d5df501ed1fa1499c41d97dbf65'
This commit is contained in:
@@ -3,18 +3,10 @@ title: RenderShortcodes
|
||||
description: Renders all shortcodes in the content of the given page, preserving the surrounding markup.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
related:
|
||||
- methods/page/Content
|
||||
- methods/page/Summary
|
||||
- methods/page/ContentWithoutSummary
|
||||
- methods/page/RawContent
|
||||
- methods/page/Plain
|
||||
- methods/page/PlainWords
|
||||
- methods/page/RenderString
|
||||
returnType: template.HTML
|
||||
signatures: [PAGE.RenderShortcodes]
|
||||
toc: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: template.HTML
|
||||
signatures: [PAGE.RenderShortcodes]
|
||||
---
|
||||
|
||||
{{< new-in 0.117.0 />}}
|
||||
@@ -23,7 +15,7 @@ Use this method in shortcode templates to compose a page from multiple content f
|
||||
|
||||
For example:
|
||||
|
||||
{{< code file=layouts/shortcodes/include.html >}}
|
||||
```go-html-template {file="layouts/shortcodes/include.html" copy=true}
|
||||
{{ with .Get 0 }}
|
||||
{{ with $.Page.GetPage . }}
|
||||
{{- .RenderShortcodes }}
|
||||
@@ -33,15 +25,15 @@ For example:
|
||||
{{ 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 >}}
|
||||
```text {file="content/about.md"}
|
||||
{{%/* include "/snippets/services" */%}}
|
||||
{{%/* include "/snippets/values" */%}}
|
||||
{{%/* include "/snippets/leadership" */%}}
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
Each of the included Markdown files can contain calls to other shortcodes.
|
||||
|
||||
@@ -58,7 +50,7 @@ Use the latter for the "include" shortcode described above.
|
||||
|
||||
To understand what is returned by the `RenderShortcodes` method, consider this content file
|
||||
|
||||
{{< code file=content/about.md lang=text >}}
|
||||
```text {file="content/about.md"}
|
||||
+++
|
||||
title = 'About'
|
||||
date = 2023-10-07T12:28:33-07:00
|
||||
@@ -67,7 +59,7 @@ date = 2023-10-07T12:28:33-07:00
|
||||
{{</* ref "privacy" */>}}
|
||||
|
||||
An *emphasized* word.
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
With this template code:
|
||||
|
||||
@@ -90,7 +82,7 @@ Note that the shortcode within the content file was rendered, but the surroundin
|
||||
|
||||
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:
|
||||
|
||||
```
|
||||
```text
|
||||
WARN .RenderShortcodes detected inside HTML block in "/content/mypost.md"; this may not be what you intended ...
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user