Hey guys, I’m a beginner to hugo and I’m trying to make my site and learn basics of html and css from scratch. I have following question in my single.html in partials. (I’m using hugo x-min as base)
{{ with .Params.author }}<h2 class="author">{{ . }}</h2>{{ end }}
{{ if and (gt .Params.date 0) ( .Params.author ) }}<h5 class="date">{{ .Date.Format "2006/01/02" }}
</h5>{{ end }}
As you can see in the second line, I want to display author name besides date like in the first line it is achieved by a simple ‘.’
The first line is a with. With always has it’s “value” in the .. The second line is an if. If just is a conditional that is executed when it’s parameters are true.
What do you want to achieve?
Show the date if an author is set AND a date is set? Probably like this:
{{ with .Params.author }}
<h2 class="author">{{ . }}</h2>
{{ with $.Date }}
<h5 class="date">{{ .Format "2006/01/02" }}</h5>
{{ end }}
{{ end }}
The $ goes “back up to the page” and inside of the $ with $.Date it’s a . that refers to $.Date. So .Format will format the $.Date available.
to get them together… but that code might also touch other h2 and h5 tags. You might have another div around those tags and then do the following to target only the headers: