Errors with "type template.HTML should be string" with hugo 0.16.0

When I attempt to build our (working on 0.15) site, I get a slew of errors similar to this one:

ERROR: 2016/06/06 11:07:23 general.go:222: Error while rendering page events/2016-amsterdam/speakers.md: template: theme/speakers/single.html:14:25: executing "theme/speakers/single.html" at <index .Site.Data.spe...>: error calling index: value has type template.HTML; should be string

For reference, the speakers.md file is basically blank (it calls a template based upon the type):

+++
date = "2016-03-06T21:17:14-06:00"
heading = "devopsdays Amsterdam - Speakers"
title = "speakers"
type = "speakers"

+++

And this is the template it is using:

{{ partial "event_header.html" . }}

{{ $path := split $.Source.File.Path "/" }}
{{ $event_slug := index $path 1 }}
{{ $e :=  (index $.Site.Data.events $event_slug) }}
<!-- end event header partial -->
<div>
      {{ .Content }}
</div>


 <!-- speaker page code begin -->

  {{ range $fname, $s := index .Site.Data.speakers (chomp $e.year) (lower $e.city) }}
<div class="row">
    <div class="col-md-3">
        <img alt = "{{ $s.name }}" src = "/events/{{ $event_slug }}/speakers/{{$fname}}.jpg" class="img-responsive" width = "250px">
    </div>
    <div class= "col-md-8">
       <h3><a href="/events/{{ $event_slug }}/program/{{$fname}}">{{ $s.name }}</a></h3>
       {{ if $s.twitter }} <a href="https://twitter.com/{{ $s.twitter }}">@{{ $s.twitter }}</a><br>{{ end }}
     <br>
     {{ $s.bio | markdownify }}
<hr>
    </div>
</div>

  {{ end }}


<!-- speaker code end -->

</div> <!-- closes the col-md-8 div from event_header -->
{{ partial "sponsors.html" . }}
</div> <!-- closes the row div -->

{{ partial "footer.html" . }}

Curious. Is this a public site on GitHub? (that I can clone and test)

I’m a dummy. I thought I had put the link to the repo here (but I was confusing myself with the ulimit issue I had on GH).

The repo is public at https://github.com/devopsdays/devopsdays-web

We get slightly different output from hugo -v than from hugo server -w. Here are two gists with the output:

hugo server -w output

hugo -v output

OK, this is my mistake … At one point during the 0.16 release the chomp method’s return value got changed to template.HTML … Which index, surprisingly enough, does not handle …

Your workaround is to wrap it in a string func:

(string (chomp $e.year))

I will create an issue about chomp vs index.

That did it! Thanks!

Edit: It’s not backwards compatible with 0.15 though; when I build the site with 0.15 I get:

ERROR: 2016/06/06 Error while rendering page events/2016-amsterdam/speakers.md: html/template: "theme/speakers/single.html" is an incomplete template

We’ll have to hold off on this merge until all of our contributors are on 0.16 I suppose :slight_smile:

You can use print to get it backwards compatible:

(print (chomp $e.year))

Tada! That did it. Thanks again. You rock.

Also see https://github.com/spf13/hugo/issues/2187