.Get returns string with double quotes

I was building a shortcode that includes some javascript and parameters:

{{% panorama type="equirectangular" image="31138750083_5e3bfa7df6_o.jpg" showControls="true" autoload="true" author="Benjamim" autorotate="1" %}}

And it populates the html with the following:

<script>
		pannellum.viewer('panorama', {
		    "type": '{{ .Get "type" }}',
		    "panorama": '{{ .Get "image" }}',
        "showControls": {{ .Get "showControls" }},
        "autoLoad": {{ .Get "autoload" }} ,
        "author": "{{ .Get "author" }}",
        "autoRotate": {{ .Get "autorotate"}}
		});
</script>

The problem is that autoload should just return true and instead returns "true" with the double quotes.

Is this an expected behaviour or am I missing something?

Looks like it has something to do with the shortcode definition being wrapped in <script> tags.

So if the definition is updated to be:

pannellum.viewer('panorama', {
    "type": '{{ .Get "type" }}',
    "panorama": '{{ .Get "image" }}',
    "showControls": {{ .Get "showControls" }},
    "autoLoad": {{ .Get "autoload" }},
    "author": "{{ .Get "author" }}",
    "autoRotate": {{ .Get "autorotate"}}
});

Then it outputs correctly:

pannellum.viewer('panorama', {
    "type": 'equirectangular',
    "panorama": '31138750083_5e3bfa7df6_o.jpg',
    "showControls": true,
    "autoLoad": true,
    "author": "Benjamim",
    "autoRotate": 1
});

So a workaround for now would be to call your shortcode like this:

<script>
{{% panorama type="equirectangular" image="31138750083_5e3bfa7df6_o.jpg" showControls="true" autoload="true" author="Benjamim" autorotate="1" %}}
</script>
2 Likes

You are right, the problem was in the script tag and I looked in the documentation to find out there is a safeJS function that I didn’t know about.

This now works: "autoLoad": {{ $autoload | safeJS }},

Thank You! :smiley:

2 Likes