Site.Params returns garbage

Hi,

Trying to setup a site-wide parameter to store a base URL. In config.yaml:


params:
  apiBaseURL: localhost:8081

And used in a layout partial like this:

<script type="text/javascript" id="scriptNav"
data-assetUrl="{{ $.Site.Params.apiBaseURL }}/public/assets/"
src="{{ $jsBaseBundle.Permalink }}" integrity="{{ $jsBaseBundle.Data.Integrity }}" crossorigin="anonymous"></script>

However, data-assetUrl will contain: data-assetUrl="#ZgotmplZ/public/assets/"

Any idea where #ZgotmplZ is coming from?

It’s an indicator that something is wrong.

My first guess would be to quote the value, e.g.

params:
  apiBaseURL: "localhost:8081"

You may want to read more on safeHTMLAttr function.

<script type="text/javascript" id="scriptNav"
++ data-assetUrl="{{ print $.Site.Params.apiBaseURL "/public/assets/" | safeHTMLAttr }}"
src="{{ $jsBaseBundle.Permalink }}" integrity="{{ $jsBaseBundle.Data.Integrity }}" crossorigin="anonymous"></script>
2 Likes

@pamubay: thank you! Added that.

@sciurius I found out by doing a {{ print $.Site.Params }} that the key should be lowercase:

map[apibaseurl:localhost:8081 languagename:English weight:1]

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