Mary
November 27, 2024, 7:04pm
1
My header-bg.ipg is here: static> images> backgrounds> header-bg.jpg
In mytheme> partials> page-title.html I have this code
<section class="page-header" style="background-image: url('{{ .Params.BgImage | relURL}}');">
...
</section>
When Hugo produces the html pages I get the expected result <section class="page-header" style="background-image: url('/images/backgrounds/header-bg.jpg');">
on all my pages (including the search results)
except the results on taxonomy pages (category) where I can see only<section class="page-header" style="background-image: url('/');">
Where should I tell Hugo that I want to see the same header-bg.jpg on all Category pages?
Mary:
.Params.BgImage
Is the context (the dot) the page? If yes, that points to a page’s front matter.
Or is there a site params value to fall back to?
Mary
November 27, 2024, 8:31pm
3
I think the dot is the page. I have the taxonomy description in config.toml
[taxonomies]
category = "categories"
format = "formats"
...
# category menu
[[menu.category]]
name = "Alcott"
URL = "categories/alcott/"
weight = 10
[[menu.category]]
name = "Tarkington"
URL = "categories/tarkington/"
weight = 20
...
Should I add here some user-defined fields?
OK, then unless you’ve set the param in front matter, this:
{{ .Params.BgImage | relURL }}
Will return /
(or /something
if you’re serving your site from a subdirectory).
A more common setup would be something like this…
site config
[params]
bgImage = '/images/backgrounds/a.jpg' # required
front matter
[params]
bgImage = '/images/backgrounds/b.jpg' # optional
template
<section class="page-header" style="background-image: url('{{ .Param "bgImage" | relURL}}');">
The template will look for a page param first, then fall back to the site param.
1 Like
system
Closed
November 29, 2024, 8:47pm
7
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.