Need help with appending a variable to another variable

In my head.html file, I am defining variables for open graph tags like so

{{- $title := .Title }}
{{- if .IsHome }}
{{- $title = site .Title }}
{{- else if and .IsSection (eq .Section "story")
{{- $title = .Title }}
<!-- more conditionals -->
{{- end }}

I want the $title for the story section to be {{ .Title }} | {{ site .Title }}. Is that possible? If so, how?

https://gohugo.io/functions/printf/

An example? For the life of me, I cannot grasp that doc section.

printf is a frequently used function that is common in most, perhaps all, programming languages. I encourage you to spend some time learning/experimenting.

{{ $a := "foo" }}
{{ $b := "bar" }}
{{ printf "%s-%s" $a $b }} --> foo-bar
2 Likes

The docs on functions are very brief and concise. This is easier to grasp.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.