Hi guys,
I need some help understand isset
and technical “data type” for .Site
:
The isset
docstring says:
Takes either a slice, array or channel and an index or a map and a key as input.
So looks like isset
takes 2 arguments:
- slice, array or channel-and-index or a map and
- a key
{{ if isset .Site.Params "isso" }}
works…
So,
- Probably
.Site.Params
is one of: slice, array or channel-and-index or map. What is it exactly? - “isso” is the key.
But the same way, {{ if isset .Site "DisqusShortname" }}
does not work. Why?
- If
.Site
is none of: slice, array,channel-and-index, map, then what is it? - Isn’t
"DisqusShortname"
a key in.Site
?
On another note, can this:
Takes either a slice, array or channel and an index or a map and a key as input.
be rephrased to something like below for clarity? Or something more correct than below, because the multiple ands and ors look confusing and I can’t tell which phrase is for 1st arg and which for 2nd.
Takes 2 input arguments: (1) either a slice, array or channel-and-index or a map, and (2) a key.
Solution
The problem was 2-fold:
- I was using
isset
for an invalid variable type. Apparently theDisqusShortname
datatype cannot be used as the 2nd arg toisset
. - As someone not knowing the go-lang, this was not obvious. So
hugo
should have thrown an error if a user like me made such a mistake. This will be fixed in the 0.20 release, thanks to @moorereason (PR 3093).
After the above PR merge in the master branch, if I do isset .Site "DisqusShortname"
, I get:
ERROR 2017/03/01 18:19:13 Error while rendering “page posts/installing-go-toolchain.md”: template: /home/kmodi/hugo/kaushalmodi.gitlab.io/themes/refined/layouts/_default/baseof.html:45:10: executing “after_main” at <isset .Site "DisqusS…>: error calling isset: unsupported type “ptr”
So the solution is to use {{ with .Site.DisqusShortname }}
instead.