Debian Codegraph @

docs/content/en/shortcodes/figure.md

raw
1 ---
2 title: Figure shortcode
3 linkTitle: Figure
4 description: Insert an HTML figure element into your content using the figure shortcode.
5 categories: []
6 keywords: []
7 ---
8
9 > [!NOTE]
10 > To override Hugo's embedded `figure` shortcode, copy the [source code][] to a file with the same name in the `layouts/_shortcodes` directory.
11
12 ## Example
13
14 With this Markdown:
15
16 ```md
17 {{</* figure
18 src="/images/examples/zion-national-park.jpg"
19 alt="A photograph of Zion National Park"
20 link="https://www.nps.gov/zion/index.htm"
21 caption="Zion National Park"
22 class="ma0 w-75"
23 */>}}
24 ```
25
26 Hugo renders this HTML:
27
28 ```html
29 <figure class="ma0 w-75">
30 <a href="https://www.nps.gov/zion/index.htm">
31 <img
32 src="/images/examples/zion-national-park.jpg"
33 alt="A photograph of Zion National Park"
34 >
35 </a>
36 <figcaption>
37 <p>Zion National Park</p>
38 </figcaption>
39 </figure>
40 ```
41
42 Which looks like this in your browser:
43
44 {{< figure
45 src="/images/examples/zion-national-park.jpg"
46 alt="A photograph of Zion National Park"
47 link="https://www.nps.gov/zion/index.htm"
48 caption="Zion National Park"
49 class="ma0 w-75"
50 >}}
51
52 ## Arguments
53
54 `src`
55 : (`string`) The `src` attribute of the `img` element. Typically this is a [page resource](g) or a [global resource](g).
56
57 `alt`
58 : (`string`) The `alt` attribute of the `img` element.
59
60 `width`
61 : (`int`) The `width` attribute of the `img` element.
62
63 `height`
64 : (`int`) The `height` attribute of the `img` element.
65
66 `loading`
67 : (`string`) The `loading` attribute of the `img` element.
68
69 `class`
70 : (`string`) The `class` attribute of the `figure` element.
71
72 `link`
73 : (`string`) The `href` attribute of the anchor element that wraps the `img` element.
74
75 `target`
76 : (`string`) The `target` attribute of the anchor element that wraps the `img` element.
77
78 `rel`
79 : (`rel`) The `rel` attribute of the anchor element that wraps the `img` element.
80
81 `title`
82 : (`string`) Within the `figurecaption` element, the title is at the top, wrapped within an `h4` element.
83
84 `caption`
85 : (`string`) Within the `figurecaption` element, the caption is at the bottom and may contain plain text or markdown.
86
87 `attr`
88 : (`string`) Within the `figurecaption` element, the attribution appears next to the caption and may contain plain text or markdown.
89
90 `attrlink`
91 : (`string`) The `href` attribute of the anchor element that wraps the attribution.
92
93 ## Image location
94
95 The `figure` shortcode resolves internal Markdown destinations by looking for a matching [page resource](g), falling back to a matching [global resource](g). Remote destinations are passed through, and the render hook will not throw an error or warning if unable to resolve a destination.
96
97 You must place global resources in the `assets` directory. If you have placed your resources in the `static` directory, and you are unable or unwilling to move them, you must mount the `static` directory to the `assets` directory by including both of these entries in your project configuration:
98
99 {{< code-toggle file=hugo >}}
100 [[module.mounts]]
101 source = 'assets'
102 target = 'assets'
103
104 [[module.mounts]]
105 source = 'static'
106 target = 'assets'
107 {{< /code-toggle >}}
108
109 [source code]: <{{% eturl figure %}}>