Putting an "author" into blog postings from metadata

I have tried various ways to have a “byline” and copyright support for multiple authors using hugo. I’ve tried multiple ways of expressing it as a variable and then generating it in a template but have come up short. What I wanted to do was have a generic author = “whoever” in the config.toml file, be able to override it in the the blog post metadata, and generate a byline in the blog post and change the copyright to the author.

I’ve tried things like $.Params(“author”), $.Params.author, and other forms of template variables to no effect, not parsed, returns nil, etc (I’m using 1.5), here for example, in the footer.copyright.html partial:

        <div class="row">
            <div class="col-sm-12">
                <p>&copy; sometemplatevariable <br></p>

What am I doing wrong??

Are you using brackets for sometemplatevariable?

<p>&copy; {{ $.Params.author }}<br></p>

Also, make sure you are passing in a context to the partial:

{{ partial "footer.copyright.html" . }}

Notice the trailing . as the final parameter to partial.

The trailing . is there. All that version renders is a blank space (no error) on the copyright message.

My config.toml looks like this:

baseurl = "http://blog.cerowrt.org/"
languageCode = "en-us"
title = "CeroWrt Lives!"
canonifyurls = true
author = “Dave Täht”

I’ve also tried adding:

author = “Dave Täht”

<p>&copy; {{if .Params.author}}{{.Params.author}}{{else}}{{ .Site.Params.author }}{{end}}<br></p>

Assuming that you have something like the following in the front matter of your content file:

title: My Title
author: Jon Doe

And keep the following in your config.toml file but remove it from the list of out-of-the-box variables:

    author = "Dave Taht"

Does that work?

Thank you VERY much!: http://blog.cerowrt.org/

Thanks @rdwatters this works like a Boss! I am using it in my META tag to specify the author of the site / page.

@Dave_Taht I noticed that the author META is specified , but empty on your website’s blog posts.

Ex: On your latest post:

<meta name="description" content="Comparing theoretical results with reality for fq-codel, the next generation">
<meta name="author" content="">

The following code, adapted from @rdwatters’ answer, works for me. (There might be a shorter syntax).

<meta property="author" content="{{if .Params.author}}{{.Params.author}}{{else}}{{ .Site.Params.author }}{{end}}" />

1 Like