Merge commit '5be51ac3db225d5df501ed1fa1499c41d97dbf65'

This commit is contained in:
Bjørn Erik Pedersen
2025-04-10 13:04:51 +02:00
987 changed files with 12379 additions and 14083 deletions

View File

@@ -3,17 +3,17 @@ title: HasShortcode
description: Reports whether the given shortcode is called by the given page.
categories: []
keywords: []
action:
related: []
returnType: bool
signatures: [PAGE.HasShortcode NAME]
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/
{{< code file=contents/example.md lang=markdown >}}
```text {file="content/example.md"}
{{</* plotly */>}}
{
"data": [
@@ -25,21 +25,21 @@ By example, let's use [Plotly] to render a chart:
],
}
{{</* /plotly */>}}
{{< /code >}}
```
The shortcode is simple:
{{< code file=layouts/shortcodes/plotly.html >}}
```go-html-template {file="layouts/shortcodes/plotly.html"}
{{ $id := printf "plotly-%02d" .Ordinal }}
<div id="{{ $id }}"></div>
<script>
Plotly.newPlot(document.getElementById({{ $id }}), {{ .Inner | safeJS }});
</script>
{{< /code >}}
```
Now we can selectively load the required JavaScript on pages that call the "plotly" shortcode:
{{< code file=layouts/baseof.html >}}
```go-html-template {file="layouts/_default/baseof.html"}
<head>
...
{{ if .HasShortcode "plotly" }}
@@ -47,4 +47,4 @@ Now we can selectively load the required JavaScript on pages that call the "plot
{{ end }}
...
</head>
{{< /code >}}
```