|
| 1 | +--- |
| 2 | +title: Figure |
| 3 | +description: Insert an HTML figure element into your content using the figure shortcode. |
| 4 | +categories: [shortcodes] |
| 5 | +keywords: [] |
| 6 | +menu: |
| 7 | + docs: |
| 8 | + parent: shortcodes |
| 9 | + weight: |
| 10 | +weight: |
| 11 | +toc: true |
| 12 | +--- |
| 13 | + |
| 14 | +{{% note %}} |
| 15 | +To override Hugo's embedded `figure` shortcode, copy the [source code] to a file with the same name in the layouts/shortcodes directory. |
| 16 | + |
| 17 | +[source code]: {{% eturl figure %}} |
| 18 | +{{% /note %}} |
| 19 | + |
| 20 | +## Example |
| 21 | + |
| 22 | +With this markup: |
| 23 | + |
| 24 | +```text |
| 25 | +{{</* figure |
| 26 | + src="/images/examples/zion-national-park.jpg" |
| 27 | + alt="A photograph of Zion National Park" |
| 28 | + link="https://www.nps.gov/zion/index.htm" |
| 29 | + caption="Zion National Park" |
| 30 | + class="ma0 w-75" |
| 31 | +*/>}} |
| 32 | +``` |
| 33 | + |
| 34 | +Hugo renders this HTML: |
| 35 | + |
| 36 | +```html |
| 37 | +<figure class="ma0 w-75"> |
| 38 | + <a href="https://www.nps.gov/zion/index.htm"> |
| 39 | + <img |
| 40 | + src="/images/examples/zion-national-park.jpg" |
| 41 | + alt="A photograph of Zion National Park" |
| 42 | + > |
| 43 | + </a> |
| 44 | + <figcaption> |
| 45 | + <p>Zion National Park</p> |
| 46 | + </figcaption> |
| 47 | +</figure> |
| 48 | +``` |
| 49 | + |
| 50 | +Which looks like this in your browser: |
| 51 | + |
| 52 | +{{< figure |
| 53 | + src="/images/examples/zion-national-park.jpg" |
| 54 | + alt="A photograph of Zion National Park" |
| 55 | + link="https://www.nps.gov/zion/index.htm" |
| 56 | + caption="Zion National Park" |
| 57 | + class="ma0 w-75" |
| 58 | +>}} |
| 59 | +
|
| 60 | +## Arguments |
| 61 | + |
| 62 | +{{< comment >}} |
| 63 | +TODO The last thing to do is reword all of these. |
| 64 | +{{< /comment >}} |
| 65 | + |
| 66 | +src |
| 67 | +: (`string`) URL of the image to be displayed. |
| 68 | + |
| 69 | +class |
| 70 | +: (`string`) The `class` attribute of the `figure` element. |
| 71 | + |
| 72 | +alt |
| 73 | +: (`string`) Alternate text for the image if the image cannot be displayed. |
| 74 | + |
| 75 | +loading |
| 76 | +: (`string`) The `loading` attribute of the `img` element. |
| 77 | + |
| 78 | +height |
| 79 | +: (`int`) The `height` attribute of the `img` element. |
| 80 | + |
| 81 | +width |
| 82 | +: (`int`) The `width` attribute of the `img` element. |
| 83 | + |
| 84 | +title |
| 85 | +: (`string`) Image title. |
| 86 | + |
| 87 | +caption |
| 88 | +: (`string`) Image caption. Markdown within the value of `caption` will be rendered. |
| 89 | + |
| 90 | +link |
| 91 | +: (`string`) If the image needs to be hyperlinked, URL of the destination. |
| 92 | + |
| 93 | +target |
| 94 | +: (`string`) Applicable if the `link` argument is set, the `target` attribule of the anchor element. |
| 95 | + |
| 96 | +rel |
| 97 | +: (`string`) Optional `rel` attribute for the URL if `link` argument is set. |
| 98 | + |
| 99 | +attr |
| 100 | +: (`string`) Image attribution text. Markdown within the value of `attr` will be rendered. |
| 101 | + |
| 102 | +attrlink |
| 103 | +: (`string`) If the attribution text needs to be hyperlinked, URL of the destination. |
| 104 | + |
| 105 | +## Image location |
| 106 | + |
| 107 | +The `figure` shortcode resolves internal Markdown destinations by looking for a matching [page resource], falling back to a matching [global resource]. Remote destinations are passed through, and the render hook will not throw an error or warning if unable to resolve a destination. |
| 108 | + |
| 109 | +[page resource]: /getting-started/glossary/#page-resource |
| 110 | +[global resource]: /getting-started/glossary/#global-resource |
| 111 | + |
| 112 | +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 site configuration: |
| 113 | + |
| 114 | +{{< code-toggle file=hugo >}} |
| 115 | +[[module.mounts]] |
| 116 | +source = 'assets' |
| 117 | +target = 'assets' |
| 118 | + |
| 119 | +[[module.mounts]] |
| 120 | +source = 'static' |
| 121 | +target = 'assets' |
| 122 | +{{< /code-toggle >}} |
0 commit comments