I would like to set a parameter like .Site.Params.Description from within a page, so that I can use it in the site’s meta description, to override what I set in my site config.
Being new to Hugo and not knowing Go, I tried the following, which failed:
{{ $.Site.Params.Description := "Hello" }}
Is this even possible? Or would the assignment of the site variable at this point be too late anyway?
I want to be able to add a meta description per page that is different from the site default description.
So in those cases, I want to override the default.
And I want it to be dynamic, e.g. including a page count if the description is for a taxonomy term or whatever.
correct me if i’m wrong, i think the simple way to have a dynamic meta description is to add description in your front matter, then you can create _index.md for each content section/page you have.
in that case you can have the dynamic meta description from _index.md , then you can use it in your template using {{ .Description }}
For example this is my meta description
<meta itemprop="description" content="{{ if .IsHome }}{{ .Site.Params.description }}{{ else }}{{ .Description }}{{ end }}">
Thanks. I do in fact have the following in my baseof.html:
<meta name="description" content="{{ if .Description }}{{ .Description }}{{ else }}{{ .Site.Params.Description }}{{ end }}">
which I got from some other thread here.
I have about 70 different taxonomy terms for “tags”, and one _index.md for each (generated by export from my previous site). So, instead of editing each _index.html, I want to put the code to create the description once in the taxonomy term template page. (In my case, /layouts/tags/tag.html).
The most obvious solution to me was the code I tried above, but that did not work.
(Also, is it possible to put variables in the front matter in .md pages?)
Thanks, I guess that will work as a workaround in the main html header template, although it seems it would have been simpler if I could just override the description directly on the taxonomy template page.