Passing query parameters in Komoot shortcode

I’m trying to write a shortcode for the Komoot website but I’m having some problems with the passing of the query parameters. The shortcode implementation is

<!-- reset scratch variables at the start -->
{{- $.Scratch.Set "k_id" false -}}
{{- $.Scratch.Set "k_profile" false -}}
{{- $.Scratch.Set "k_gallery" false -}}
{{- $.Scratch.Set "k_height" 580 -}}

{{- if .IsNamedParams -}}
  {{- $.Scratch.Set "k_id" (.Get "id") -}}
  {{- $.Scratch.Set "k_profile" (.Get "profile") -}}
  {{- $.Scratch.Set "k_gallery" (.Get "gallery") -}}
{{- else -}}
  <!-- for the positional version if any -->
{{- end -}}

{{- $.Scratch.Set "queries" slice -}}

{{- if $.Scratch.Get "k_profile" -}}
  {{- $.Scratch.Add "queries" (querify "profile" 1) -}}
  {{- $.Scratch.Set "k_height" 680 -}}
{{- end -}}

{{- if $.Scratch.Get "k_gallery" -}}
  {{- $.Scratch.Add "queries" (querify "gallery" 1) -}}
{{- end -}}

<iframe src="{{- $.Scratch.Get "k_id" -}}/embed?{{ delimit ($.Scratch.Get "queries") "&" | safeHTML }}" width="100%" height="{{ $.Scratch.Get "k_height" }}" frameborder="0" scrolling="no"></iframe>

When I use the following in my page I get the embed code but in the query parameters the assignment character is replaced with the hex code in percent notation. So the following

{{< komoot id="268099695" profile="1" >}}

will return the following code in the HTML

<iframe src="" width="100%" height="680" frameborder="0" scrolling="no"></iframe>

I’ve tried adding the safeHTML already but this doesn’t seem to work. What am I missing here?

You can’t nest double quotes ("). You need to use different quotes (’ or `).

Also, you don’t need {{ .Scratch }} I guess. You can directly use {{ .Get }}.

EDIT: I just trimmed your shortcode to only this:

<iframe src="{{ .Get `id` }}/embed?profile=1" width="100%" height="680" frameborder="0" scrolling="no"></iframe>

and it seems to work.

This is what I got on my webpage:

Try safeURL instead.

It is indeed not good practice to use the same quotes but it doesn’t throw an error. Also I could use .Get directly but this is a bit more readable for later.

This was indeed the solution!

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