pulec.foo git

zola-theme-plc-example

Example for Zola plc theme

content/04-shortcodes.md

Mode
-rw-r--r--
Size
1942 bytes
Reference
content/04-shortcodes.md@8ebfcee8b464 (last change)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
+++
title = "Shortcodes"
description = "What Zola shortcodes are, how they work, and how to create your own."
date = 2026-03-13
[taxonomies]
tags = ["howto"]
+++

Shortcodes are reusable HTML templates you invoke from markdown. Zola looks for them in `templates/shortcodes/` — either in your site root or in the theme.

## Inline vs block syntax

**Inline** shortcodes render in place:

```
{{/* shortcode_name(arg="value") */}}
```

**Block** shortcodes wrap content:

```
{%/* shortcode_name() */%}
Content goes here
{%/* end */%}
```

## Example: video shortcode

### The template

Create `templates/shortcodes/video.html`:

```html
<video controls {% if autoplay %}autoplay muted loop{% endif %}>
  <source src="{{ src }}" type="video/mp4">
</video>
```

### Usage in markdown

```
{{/* video(src="/videos/demo.mp4") */}}
{{/* video(src="/videos/bg-loop.mp4", autoplay=true) */}}
```

The first call renders a standard video player with controls. The second adds `autoplay muted loop` for a silent background loop.

## Creating your own shortcodes

1. Create a file in `templates/shortcodes/` — the filename (minus `.html`) becomes the shortcode name
2. Use Tera template syntax for parameters
3. Call it from any markdown file using `{{ name(args) }}` or `{%/* name() */%}...{%/* end */%}`

## Note on rendering

Shortcode calls in this example file will **not** render unless the corresponding template files exist in `templates/shortcodes/`. The syntax above is shown as code blocks so you can see the raw invocation.

To test shortcodes:

1. Create the template file (e.g. `templates/shortcodes/video.html`)
2. Use the shortcode syntax (without the code block) in a content page
3. Run `zola serve` to see the result

## Further reading

See the [Zola shortcodes documentation](https://www.getzola.org/documentation/content/shortcodes/) for the full reference, including body content, optional arguments, and built-in shortcodes.