Sections are working great. I get a section list page that enumerates all posts via postcards in the section with summary blurb per post and feature image using the theme Casper3. So far, so good.
I would like to enhance this and have a header background image for all of the generated section list pages. A section is like this:
+++
title = "Florida Coast"
feature_image = "/images/2020/06/7-mile-bridge.jpg"
+++
Pretty simple. The goal is for the feature_image (a variable used by casper3 for post header images and displayed by the single.html layout) to appear as the background of the header for the section list page.
I’ve looked at the single layout and how it generates the header. It tests {{ if .Param "feature_image" }} where the context is the current page. In a list page, the current context would be the section. I saw .CurrentSection as a variable.
How would I test if the section being processed by the loop has a feature_image?
{{ .Param .CurrentSection "feature image"}
Then I can display it. I might need a new class for that.
Are there examples of themes that provide for this capability. Casper3 doesn’t seem to for any taxonomy list pages.
Here is the repo on github with the link to the branch “sections” where I am setting this up and testing before merging with master: https://github.com/lewisl/a-view-hugo/tree/sections
I had to update casper3 as the last commit done was meant to include a header image. The theme uses feature_image in front matter rather than cover, or background, etc. No problem with that.
The partial for the header background does this to display the header image if present:
The index.html layout attempts to set the value of the image using Scratch. Note that the Scratch.Set happens prior to calling the header background prior.
The fact is the Scratch never contains the item “background”.
I wonder if this is a scope problem. I am going to try .Page.Scratch. Not very confident it will work but I’ll report back.
Maybe there is just an easier way: not clear this use cases raises the tempate variable scoping challenges that lead to Scratch. This seems like a very obvious thing to want to do and other themes do it.