Using parameters in shortcode parameters

I want to pass a URL value to a shortcode. The URL value depends on a parameter defined in the config.toml.
Specifically, I’m using Docsy theme with versioning and to have a target URL passed via a shortcode parameter to refer to “/docs/{{< param latest_stable_version >}}/overview” and evaluate when rendering to (e.g.,) “/docs/v1.0.1/overview”.
Using {{< param latest_stable_version >}} inside the short code parameter does not work and it renders the actual text as is.
Is it possible to pass an evaluated parameter (i.e., its value) to a shortcode?

No, it is not.

Can’t you lookup site.Params.latest_stable_version from the shortcode?

Thanks @jmooring
I could use the parameter from inside the code but then it would not be reusable.
The placement of the site.Params.latest_stable_version would be hard-coded in the shortcode.
I would like to pass in different URL patterns:

  • /install/<version>/linux
  • /docs/<version>/install/prebuilt
  • /docs/<version>/overview

I could break up the short code parameters from “href” to “href-pre” and “href-suffix” and then concat inside the shorcode, but I was hoping for a more elegant way

Can you pass a param with a placeholder then replace within the shortcode. Example:

{{< myshortcode "/foo/bar/@@x@@/baz/" >}}

yeah, that would be good.
I’m new to shortcodes, how would I code the replacements for @@x@@ with the value of the parameter?
Right now I simply use “{{ .Get url }}” in the shortcode’s html.
Would “{{ .Get url | replace @@x@@ {{ param site.Parameters.last_stable_version }} }}” work?
I would probably need to test if the passed URL contains the pattern first and only replace if it does…

Much appreciate the help!


{{< myshortcode "/foo/bar/@@/baz/" >}}
{{- $msg := "The %q shortcode requires a positional parameter in the form foo/@@/bar: see %s" }}
{{- with .Get 0 }}
  {{- if findRE `@@` . }}
    {{- $href := strings.Replace . "@@" site.Params.latest_stable_version -}}
    <a href="{{ $href }}">latest version</a>
  {{- else }}
    {{- errorf $msg $.Name $.Position }}
  {{- end }}
{{- else }}
  {{- errorf $msg .Name .Position }}
{{- end -}}

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.