I am trying to add class names to the body
. I can’t figure out how to print the template name. For example, if the page uses layouts > _default > single.html
, I’d like it to return <body class="single">
. Is there an easy way of returning the template name?
I’ve tried this already…
<body class='Type-is-{{ .Type }} Kind-is-{{ .Kind }} Section-is-{{ .Section }}'>
…which returns…
<body class="Type-is-posts Kind-is-page Section-is-posts">
Why don’t you simply include the body class you need in the respective template?
Otherwise a check like the following should do:
<body class='{{ if .IsPage }}single{{ else }}list{{ end }}'>
In Hugo a Page
refers to static pages (e.g. /about/) and other content permalink pages (e.g. blog posts)
The above use the template under /_default/single.html
Everything else in Hugo is considered a Node
(e.g. index, section lists etc) and the template under /_default/list.html
is used (unless you have configured additional templates for index, taxonomies etc).
Thanks @alexandros for responding and clearing that up. I wasn’t sure if I was missing something more.