Calling IsSet with unsupported type "invalid" (<nil>) will always return false

I’m using the robots.html partial below to add <meta name="robots" content="index, follow" /> tags to pages and posts, with the config for each page/post in front matter:

[robots]index = truefollow = true

When I run hugo server for a site at localhost, I get the warning “calling IsSet with unsupported type “invalid” () will always return false.” The error seems to be wih this file, but I don’t see it. Any ideas?

robots.html:

{{  $robotsGenerate := false -}}
{{- if or (isset $.Params.robots "index") (isset $.Params.robots "follow") }}
{{-     $robotsGenerate = true -}}
{{- else if or (isset $.Site.Params.robots "index") (isset $.Site.Params.robots "follow") -}}
{{-     $robotsGenerate = true -}}
{{- end -}}
{{- if eq $robotsGenerate true -}}
{{-     $robotsIndex := true -}}
{{-     $robotsFollow := true -}}
{{-     if isset $.Site.Params "robots" -}}
{{-         if isset $.Site.Params.robots "index" -}}
{{-             $robotsIndex = $.Site.Params.robots.index -}}
{{-         end -}}
{{-         if isset $.Site.Params.robots "follow" -}}
{{-             $robotsFollow = $.Site.Params.robots.follow -}}
{{-         end -}}
{{-     end -}}
{{-     if isset $.Params "robots" -}}
{{-         if isset $.Params.robots "index" -}}
{{-             $robotsIndex = $.Params.robots.index -}}
{{-         end -}}
{{-         if isset $.Params.robots "follow" -}}
{{-             $robotsFollow = $.Params.robots.follow -}}
{{-         end -}}
{{-     end -}}
{{-     if and (eq $robotsIndex true) (eq $robotsFollow true) }}
    <meta name="robots" content="index, follow" />
{{-     else if and (eq $robotsIndex true) (eq $robotsFollow false) }}
    <meta name="robots" content="index, nofollow" />
{{-     else if and (eq $robotsIndex false) (eq $robotsFollow true) }}
    <meta name="robots" content="noindex, follow" />
{{-     else if and (eq $robotsIndex false) (eq $robotsFollow false) }}
    <meta name="robots" content="noindex, nofollow" />
{{-     end -}}
{{- end -}}

I don’t think you want to use isset here anyway. It returns true even if you’ve set the value to false in front matter. For example, you can reduce this:

if or (isset $.Params.robots "index") (isset $.Params.robots "follow")

To this:

if or $.Params.robots.index $.Params.robots.follow

And you can use PAGE.Param (singular) instead of checking both PAGE and SITE params separately.

Thanks! That solved the error message.

I don’t quite understand this, but maybe it’s not a big deal.

However, curiously now, if I set the front matter to

[robots]index = falsefollow = false

on a page or post, no meta tag is output at all. That’s probably an exising issue with the partial.

This does output the meta tag:

[robots]index = falsefollow = true

If I correctly understand the intent, I think you can replace your existing code with:

{{ $index := cond (.Param "robots.index") "index" "noindex" }}
{{ $follow := cond (.Param "robots.follow") "follow" "nofollow" }}
{{ printf `<meta name="robots" content="%s, %s">` $index $follow | safeHTML }}

Try it:

git clone --single-branch -b hugo-forum-topic-56232 https://github.com/jmooring/hugo-testing hugo-forum-topic-56232
cd hugo-forum-topic-56232
hugo server

Thanks! That’s much simpler and works great. I can see how it works, too.

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