You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> You can highlight important information in your articles or docs using different types of callouts (also known as admonitions – or alerts, as used in [the Hugo docs](https://gohugo.io/render-hooks/blockquotes/#alerts)).
124
124
125
-
For compatibility with both content and layout files, we use a mix of shortcodes and partials to display blockquote alerts. Partials work in layout, but not content files. Shortcodes work in content, but not layout files. So you'll want to call the partial in layout files but use the shortcode (it calls the partial) in content files.
125
+
For compatibility with both content and layout files, we use a mix of shortcodes and partials to display blockquote alerts. Partials work in layout, but not content files. Shortcodes work in content, but not layout files. Use the partial in layout files, and the shortcode (which internally calls the partial) in content files.
126
126
127
127
The partial is at `site/layouts/partials/blockquote-alert.html`, and the shortcode is at `site/layouts/shortcodes/blockquote-alert.html`.
128
128
129
-
There are five alert types as shown in the examples below. Omit the `title` parameter to keep the alert type as the default title (for example, a note alert will have "Note" as its title). The descriptions for the alert types are borrowed from the Hugo docs:
129
+
There are five available alert types as shown in the examples below:
130
130
131
-
```
132
-
# Shortcodes in content files
131
+
- note
132
+
- tip
133
+
- important
134
+
- warning
135
+
- caution
136
+
137
+
Omit the `title` parameter to keep the alert type as the default title (for example, a note alert will have "Note" as its title):
For layout files, you can call the partial as shown in the examples below. Just like in the shortcode examples, any string passed into the `content` parameter is interpreted as markdown. Use `html`instead `to pass in HTML. Again, the title parameter is optional and will default to the alert type:
163
+
In layout files, call the partial directly. Just like shortcode content, anything passed to the `content` parameter is parsed as Markdown. To pass raw HTML instead, use the `html` parameter. Again, the title parameter is optional and will default to the alert type:
164
164
165
-
```
166
-
# Partials in layout files
165
+
```html
166
+
<!-- Partials in layout files -->
167
+
168
+
<!-- Anything passed via `content` is interpreted as Markdown -->
167
169
168
-
{{/* These are interpreted as Markdown */}}
169
170
{{ partial "blockquote-alert.html" (dict
170
171
"type" "note"
171
172
"title" "Optional custom title"
@@ -195,9 +196,28 @@ For layout files, you can call the partial as shown in the examples below. Just
195
196
"title" "Optional custom title"
196
197
"content" "Advises about risks or negative outcomes."
197
198
) }}
199
+
```
200
+
201
+
In addition to simple string content as shown above, you can also pass in complex nested content with multiple paragraphs and elements:
198
202
199
-
These are also valid:
203
+
```md
204
+
<!-- Shortcode example with more complex content -->
This is a tip with **bold text** and _italic_ text.
208
+
209
+
This is a second paragraph in the same alert.
210
+
211
+
- List item 1
212
+
- List item 2
213
+
{{< /blockquote-alert >}}
214
+
```
215
+
216
+
You can do similar in partials. These are all valid options. Additionally, you can assign content to a variable before passing it in, which helps with formatting in longer templates:
217
+
218
+
```html
219
+
<!-- You can wrap your markdown content in backticks if it doesn't itself contain backticks -->
220
+
<!-- Note that indented lines could be interpreted as a preformatted code block. -->
201
221
{{ $alertContent := `This is a tip with **bold text** and _italic_ text.
202
222
203
223
This is a second paragraph in the same alert.
@@ -212,7 +232,7 @@ This is a second paragraph in the same alert.
This is a tip with **bold text** and _italic_ text.
238
-
239
-
This is a second paragraph in the same alert.
240
-
241
-
- List item 1
242
-
- List item 2
243
-
{{< /blockquote-alert >}}
244
-
245
-
# Partial in layout files
246
-
247
-
{{ partial "blockquote-alert.html" (dict
248
-
"type" "tip"
249
-
"title" "Optional custom title"
250
-
"content" "<p>Helpful advice for doing things better or more easily.</p>"
251
-
) }}
252
249
250
+
<!-- Pass HTML with nested elements -->
253
251
{{ partial "blockquote-alert" (dict
254
252
"type" "caution"
255
253
"title" "Be Careful!"
256
-
"content" "<p>This is a <strong>caution</strong> message.</p><p>It has multiple paragraphs.</p>"
254
+
"html" "<p>This is a <strong>caution</strong> message.</p><p>It has multiple paragraphs.</p>"
257
255
) }}
258
256
```
259
257
260
-
```
261
-
{{ $alertContent := `This is a tip with **bold text** and _italic_ text.
262
-
263
-
This is a second paragraph in the same alert.
264
-
265
-
- List item 1
266
-
- List item 2
267
-
`}}
268
-
269
-
270
-
{{ $alertContent := add
271
-
"This is a tip with **bold text** and _italic_ text.\n\n"
272
-
"This is a second paragraph in the same alert.\n"
273
-
"- List item 1\n"
274
-
"- List item 2\n\n"
275
-
"`Here's some text in backticks.`"
276
-
}}
277
-
278
-
**NOTE:**
279
258
280
-
You'll want to handle line breaks properly within the content string in partials when working with complex content. For example, the following will throw a parse error (`html: overlay: parse failed unterminated quoted string in action`):
259
+
> [!IMPORTANT]
260
+
> When working with complex content, make sure to handle line breaks properly within the strings passed to the `content` or `html` parameters. For example, the following will throw a parse error (`html: overlay: parse failed unterminated quoted string in action`):
281
261
282
262
```
283
263
{{ partial "blockquote-alert" (dict
284
264
"type" "caution"
285
265
"title" "Be Careful!"
286
-
"content" "<p>This is a <strong>caution</strong> message.</p>
266
+
"html" "<p>This is a <strong>caution</strong> message.</p>
287
267
<p>It has multiple paragraphs.</p>"
288
268
) }}
289
269
```
290
270
291
-
To fix this, use either of these options:
271
+
To avoid this, you can use either of the following options:
292
272
293
273
- Keep everything on a single line
294
274
- Use string concatenation (whether in a variable or directly)
295
275
296
-
```
297
-
<!-- Option #1: Keep everything on a single line -->
298
-
{{ partial "blockquote-alert" (dict
299
-
"type" "caution"
300
-
"title" "Be Careful!"
301
-
"content" "<p>This is a <strong>caution</strong> message.</p><p>It has multiple paragraphs.</p>"
302
-
) }}
303
-
304
-
---------------
305
-
<!-- Option #2: Use string concatenation (whether in a variable or directly) -->
306
-
307
-
{{ $alertContent := add
308
-
"<p>This is a <strong>caution</strong> message.</p>"
309
-
"<p>It has multiple paragraphs.</p>"
310
-
}}
311
-
312
-
{{ partial "blockquote-alert.html" (dict
313
-
"type" "caution"
314
-
"title" "Be Careful!"
315
-
"content" $alertContent
316
-
) }}
317
-
318
-
This is a tip with **bold text** and _italic_ text.
For controlling what HTML is rendered, you need to work with the site templates. In the directory, `site/layouts/`, you'll find a number of HTML files with various template tags. The first file to check out is `site/layouts/_default/baseof.html` - this is the base layout Hugo uses to build your site that templates extend. Hugo has a lookup order for associating a content entry to a template. A single entry whose type is post (`type: post`), Hugo will look for a layout in `site/layouts/post/single.html`, and if that does not exist, it will fallback to `site/layouts/_default/single.html`.
0 commit comments