Hello folks,
I’d like to implement a shortcode which supports getting its working content either from .Inner
, or a file=
parameter pointing to a javascript file to load.
My shortcode works fine with the code below, but what I have noticed is, as soon as I mention .Inner
in the shortcode – even in a branch which is never executed – the page content terminates immediately after the first calling of the shortcode.
Here’s my example:
{{- $width := cond .IsNamedParams (.Get "width") (.Get 0) | default "100%" -}}
{{- $height := cond .IsNamedParams (.Get "height") (.Get 1) | default "30rem" -}}
{{- $chart_filename := (.Get "file") -}}
{{- $scratch := newScratch -}}
{{- $scratch.Set "absolute_filename" "" -}}
{{- with .Get "file" -}}
{{- $chart_name := index (split (path.Base $chart_filename) ".") 0 -}}
{{- $chart_absolute_filename := add "/" $chart_filename -}}
{{- $scratch.Set "absolute_filename" $chart_absolute_filename -}}
{{- $id := add "echart_" $chart_name -}}
{{- $scratch.Set "divid" $id -}}
{{- else -}}
{{- $content := .Inner | transform.Unmarshal | jsonify -}}
{{- $id := dict "Content" $content "Scratch" .Page.Scratch | partial "function/id.html" -}}
{{- $scratch.Set "divid" $id -}}
{{ errorf "Provide either 'file=' parameter, or content of chart to display." }}
{{- end -}}
{{ $id := $scratch.Get "divid" }}
{{ $chart_absolute_filename := $scratch.Get "absolute_filename" }}
<div class="echarts" data-filename="{{- $chart_absolute_filename -}}" id="{{ $id }}" style="width: {{ $width }}; height: {{ $height }};"></div>
{{- .Page.Scratch.SetInMap "this" "echarts" true -}}
Notice:
- As soon as I replace
.Inner
with a string literal (e.g.""
), all works. - I only call the shortcode with a “file” parameter, so the branch with the
.Inner
mention is never actually triggered.
Any hint? Thanks!