Goal
Set a background image in SASS that references a configuration defined in other pages (my config.yml
and other page’s front matter featImg: project/project-widescreen.jpg
). I prefer to use background-image
for accessibility reasons.
My Code
The tutorial I’m following had me set up a configuration in my config.yml
to define the path from the parent folder down to the page specific folder: path-to-CS-images:
. I’ve tried setting it to /assets/images/case-studies/
and ../images/case-studies/
(is one better practice over the other?). So my path goes something like this:
background-image: url('/{{ site.baseurl }}{{ site.path-to-CS-images }}{{ page.featImg }}')
But it still can’t find the image. The direct path to the image does work though
background-image: url('../images/case-studies/project/project-widescreen.jpg')
Other things I’ve tried that didn’t work
background-image: url('#{"/{{ site.baseurl }}{{ site.path-to-CS-images }}{{ page.featImg }}"}')
- renaming my homepage file from index.sass to index.sass.liquid.
Please let me know if I should include more of my code.
I’ve seen a few other threads on this issue, but I’m obviously missing something because I can’t get their solutions to work for me.
I know the tutorial I’m following doesn’t always follow best practices, but I’m still learning what those best practices would be, so it’s a lot of trial and error. How much of the url should I even be making Liquid? I’m going to have a lot of images on each page, should I just write out the direct path for all of them?