--- title: HasShortcode description: Reports whether the given shortcode is called by the given page. categories: [] keywords: [] params: functions_and_methods: returnType: bool signatures: [PAGE.HasShortcode NAME] --- By example, let's use [Plotly] to render a chart: [Plotly]: https://plotly.com/javascript/ ```text {file="content/example.md"} {{}} { "data": [ { "x": ["giraffes", "orangutans", "monkeys"], "y": [20, 14, 23], "type": "bar" } ], } {{}} ``` The shortcode is simple: ```go-html-template {file="layouts/_shortcodes/plotly.html"} {{ $id := printf "plotly-%02d" .Ordinal }}
``` Now we can selectively load the required JavaScript on pages that call the "plotly" shortcode: ```go-html-template {file="layouts/baseof.html"} ... {{ if .HasShortcode "plotly" }} {{ end }} ... ```