How to humanize the title of tag pages?

Hello!

I’m trying to use the humanize function on tag pages so that, on those pages, the title appears correctly. For instance, the tag “blockbuster-action-movies” to “blockbuster action movies”. According to the humanize documentation I can use the function for that:

{{humanize "my-first-post"}} → "My first post"

But I can’t get it working (in layouts/_default/list.html):

{{ humanize .Title }}

and

{{ humanize (string .Title) }}

Both return (Hugo 0.16):

Started building site
panic: runtime error: slice bounds out of range [recovered]
panic: runtime error: slice bounds out of range

goroutine 1 [running]:
panic(0xba39c0, 0xc082002040)
/usr/local/Cellar/go/1.6.2/libexec/src/runtime/panic.go:481 +0x3f4
text/template.errRecover(0xc082302dd0)
/usr/local/Cellar/go/1.6.2/libexec/src/text/template/exec.go:133 +0xf5
panic(0xba39c0, 0xc082002040)
/usr/local/Cellar/go/1.6.2/libexec/src/runtime/panic.go:443 +0x4f7
github.com/bep/inflect.(*Ruleset).Humanize(0xc0821b4e00, 0xc0824a5319, 0x0, 0x0, 0x0)
/Users/spf13/gopath/src/github.com/bep/inflect/inflect.go:415 +0x26c
github.com/bep/inflect.Humanize(0x0, 0x0, 0x0, 0x0)
/Users/spf13/gopath/src/github.com/bep/inflect/inflect.go:592 +0x4a
github.com/spf13/hugo/tpl.humanize(0xa835a0, 0xc0823e9690, 0x0, 0x0, 0x0, 0x0)
/Users/spf13/gopath/src/github.com/spf13/hugo/tpl/template_funcs.go:1708 +0xab
reflect.Value.call(0xb2dda0, 0xe18508, 0x13, 0xc80100, 0x4, 0xc0823e9620, 0x1, 0x1, 0x0, 0x0, …)
/usr/local/Cellar/go/1.6.2/libexec/src/reflect/value.go:435 +0x1214
reflect.Value.Call(0xb2dda0, 0xe18508, 0x13, 0xc0823e9620, 0x1, 0x1, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.6.2/libexec/src/reflect/value.go:303 +0xb8
text/template.(*state).evalCall(0xc082302d60, 0xc43240, 0xc082492360, 0x16, 0xb2dda0, 0xe18508, 0x13, 0x3bcab0, 0xc08239
fd70, 0xc082000e4a, …)
/usr/local/Cellar/go/1.6.2/libexec/src/text/template/exec.go:641 +0xb40
text/template.(*state).evalFunction(0xc082302d60, 0xc43240, 0xc082492360, 0x16, 0xc08239fda0, 0x3bcab0, 0xc08239fd70, 0x
c08239d160, 0x2, 0x2, …)
/usr/local/Cellar/go/1.6.2/libexec/src/text/template/exec.go:515 +0x33d
text/template.(*state).evalCommand(0xc082302d60, 0xc43240, 0xc082492360, 0x16, 0xc08239fd70, 0x0, 0x0, 0x0, 0x0, 0x0, …
.)
/usr/local/Cellar/go/1.6.2/libexec/src/text/template/exec.go:412 +0x1f0
text/template.(*state).evalPipeline(0xc082302d60, 0xc43240, 0xc082492360, 0x16, 0xc082393d10, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.6.2/libexec/src/text/template/exec.go:385 +0x187
text/template.(*state).walk(0xc082302d60, 0xc43240, 0xc082492360, 0x16, 0x3b8910, 0xc08239fe60)
/usr/local/Cellar/go/1.6.2/libexec/src/text/template/exec.go:215 +0x13c
text/template.(*state).walk(0xc082302d60, 0xc43240, 0xc082492360, 0x16, 0x34285d0, 0xc08239fc80)
/usr/local/Cellar/go/1.6.2/libexec/src/text/template/exec.go:223 +0x6a8
text/template.(*Template).Execute(0xc08239bc40, 0x3babc0, 0xc0820e1340, 0xc43240, 0xc082492360, 0x0, 0x0)
/usr/local/Cellar/go/1.6.2/libexec/src/text/template/exec.go:178 +0x2ae
html/template.(*Template).Execute(0xc08239fc20, 0x3babc0, 0xc0820e1340, 0xc43240, 0xc082492360, 0x0, 0x0)
/usr/local/Cellar/go/1.6.2/libexec/src/html/template/template.go:104 +0xa1
github.com/spf13/hugo/hugolib.(*Site).renderThing(0xc0822a61e0, 0xc43240, 0xc082492360, 0xc0824144c0, 0x18, 0x3babc0, 0x
c0820e1340, 0x0, 0x0)
/Users/spf13/gopath/src/github.com/spf13/hugo/hugolib/site.go:2044 +0xc9
github.com/spf13/hugo/hugolib.(*Site).render(0xc0822a61e0, 0xc0824a4f20, 0x8, 0xc43240, 0xc082492360, 0x3babc0, 0xc0820e
1340, 0xc0821ba600, 0x14, 0x20, …)
/Users/spf13/gopath/src/github.com/spf13/hugo/hugolib/site.go:2018 +0x2c5
github.com/spf13/hugo/hugolib.(*Site).renderAndWritePage(0xc0822a61e0, 0xc0824a4f20, 0x8, 0xc0823a1d49, 0x0, 0xc43240, 0
xc082492360, 0xc0821ba600, 0x14, 0x20, …)
/Users/spf13/gopath/src/github.com/spf13/hugo/hugolib/site.go:1938 +0x13c
github.com/spf13/hugo/hugolib.(*Site).renderSectionLists(0xc0822a61e0, 0x0, 0x0)
/Users/spf13/gopath/src/github.com/spf13/hugo/hugolib/site.go:1655 +0x667
github.com/spf13/hugo/hugolib.(*Site).Render(0xc0822a61e0, 0x0, 0x0)
/Users/spf13/gopath/src/github.com/spf13/hugo/hugolib/site.go:724 +0x10b
github.com/spf13/hugo/hugolib.(*Site).Build(0xc0822a61e0, 0x0, 0x0)
/Users/spf13/gopath/src/github.com/spf13/hugo/hugolib/site.go:380 +0x87
github.com/spf13/hugo/commands.buildSite(0xc082303867, 0x1, 0x1, 0x0, 0x0)
/Users/spf13/gopath/src/github.com/spf13/hugo/commands/hugo.go:688 +0x1bf
github.com/spf13/hugo/commands.build(0xc0823039ae, 0x1, 0x1, 0x0, 0x0)
/Users/spf13/gopath/src/github.com/spf13/hugo/commands/hugo.go:525 +0x3c5
github.com/spf13/hugo/commands.server(0x10a03c0, 0xc082291a10, 0x0, 0x3, 0x0, 0x0)
/Users/spf13/gopath/src/github.com/spf13/hugo/commands/server.go:163 +0x6f9
github.com/spf13/cobra.(*Command).execute(0x10a03c0, 0xc082291980, 0x3, 0x3, 0x0, 0x0)
/Users/spf13/gopath/src/github.com/spf13/cobra/command.go:561 +0x633
github.com/spf13/cobra.(*Command).ExecuteC(0x109efc0, 0x10a03c0, 0x0, 0x0)
/Users/spf13/gopath/src/github.com/spf13/cobra/command.go:651 +0x563
github.com/spf13/hugo/commands.Execute()
/Users/spf13/gopath/src/github.com/spf13/hugo/commands/hugo.go:168 +0x7e
main.main()
/Users/spf13/gopath/src/github.com/spf13/hugo/main.go:26 +0x2f

You have an empty title somewhere. If you wrap it in a {{ if }} or something it should work.

I will create a bug re. the handling of the empty string.

1 Like

Thanks bep, that solved it!

{{ .Title | humanize}}