From within a shortcode template, is there any way to determine which notation was used to call the shortcode from markdown?
{{< shortcode >}}
vs
{{% shortcode %}}
From within a shortcode template, is there any way to determine which notation was used to call the shortcode from markdown?
{{< shortcode >}}
vs
{{% shortcode %}}
No it isn’t.
Try:
{{ if strings.Contains $.Page.RawContent `{{%` }}Markdown{{ end }}
{{ if strings.Contains $.Page.RawContent `{{<` }}HTML{{ end }}
Possible Caveats:
The above checks the .RawContent
of the entire parent Page, it is not limited to the shortcode input.
The above also works without the dollar sign, but on my end it was slower without it, might be an expensive check.
Thanks, but with multiple calls to the same shortcode within one document, I wanted to know how each one was called – no guarantee of consistent user behavior. I’ll find another way…
I’m gonna make some T shirts.
This might not help too much, but may be you have an optional shortcode parameter “md” (which defaults to false), that you then check inside the shortcode.
Usage:
{{< shortcode >}}
or
{{% shortcode md=true %}}
I’m assuming this is for some shortcodes that you have developed, and not from someone else’s themes.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.