mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-14 20:37:55 -05:00
9b0050e9aa
git-subtree-dir: docs git-subtree-split: 5c085a37b297bf12f59efeaae591418ec025c10d
1.1 KiB
1.1 KiB
title | description | categories | keywords | action | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|
HasShortcode | Reports whether the given shortcode is called by the given page. |
|
By example, let's use Plotly to render a chart:
{{< code file=contents/example.md lang=markdown >}} {{</* plotly />}} { "data": [ { "x": ["giraffes", "orangutans", "monkeys"], "y": [20, 14, 23], "type": "bar" } ], } {{</ /plotly */>}} {{< /code >}}
The shortcode is simple:
{{< code file=layouts/shortcodes/plotly.html >}} {{ $id := printf "plotly-%02d" .Ordinal }}
{{< /code >}}Now we can selectively load the required JavaScript on pages that call the "plotly" shortcode:
{{< code file=layouts/baseof.html >}}
<head> ... {{ if .HasShortcode "plotly" }} {{ end }} ... </head> {{< /code >}}