Unable to get items in assets folder

I’m working on building a theme, and one of the rather obvious things I want to do is set up a background image. I have an image saved in assets/images/muir_woods_pano.jpg, but I can’t for the life of me access it.

I don’t think I’ve changed anything with respect to how Hugo should be configured to process images, but I just can’t get it to work.

In troubleshooting, I’ve gotten it down to putting the following code in my layouts/baseof.html file, and it’s still not working:

  {{ $background := resources.Get "images/muir_woods_pano.jpg" }}
  {{ printf "%s" $background.Permalink }}

$background seems to be a nil pointer, rather than accessing the image. The image is definitely there in assets\images\muir_woods_pano.jpg… but Hugo isn’t doing anything with it and doesn’t seem to be processing it or moving it to the public directory when I run hugo build or hugo serve–although that may be from the error (and if I comment out the problematic lines, then it doesn’t touch them which should mean that they don’t get moved anyways).

My theme is located in the themes directory, mainly so that I can make it a git submodule. The resources I’m trying to include are not in the theme directory, but rather the base directory, and the templates are in the theme subdirectory… but that shouldn’t matter, should it? There are a few files in the assets folder in the theme, but no overlapping subdirectories.

I’m running Hugo 0.151.2 extended on Win11 via chocolatey.

I can share code, but given that it’s not hosted anywhere currently it would be a bit difficult.

Ok, after an hour of troubleshooting, I’m still confused. However, I have gotten it to work if I put the file in my themes subfolder (i.e. themes/ambitious/assets/images/ directory)… but I shouldn’t need to put everything in there, no?

I have it set up in the config to use the theme, but then I want to be able to put my own items in the assets/images (or whatever) directory.

I am running hugo serve from the main folder, not within the theme. And it is picking up the content from my content folder for testing. But not my assets?

Without access to the project I’m only guessing, which isn’t terribly efficient for either of us.

Have you defined any mounts?

Yeah, I understand that it’s a bit difficult to troubleshoot without the code, but at the same time I’m not sure I could share an MWE that would demonstrate it, so I’m mostly trying to understand what could cause Hugo to not see files that are in the assets directory; or rather it seems cause Hugo to not merge the contents of the assets folder from a theme with the contents of the same base folder.

I only have one mount defined, as a result of trying to get tailwind css 4 working (which it is, thanks to you). But, I was under the impression that assets should be automatically mounted, per [Configure modules]

My hugo.yaml file in config/_default

# baseURL: https://example.org/
languageCode: en-us
title: New Hugo Site
theme: ambitious

imaging:
  anchor: Center

module:
  mounts:
  - disableWatch: true
    source: hugo_stats.json
    target: assets/notwatching/hugo_stats.json

build:
  buildStats:
    enable: true
  cachebusters:
  - source: assets/notwatching/hugo_stats\.json
    target: css
  - source: (postcss|tailwind)\.config\.js
    target: css

and my params.yaml file in the same directory:

copyright: "© { year } Mike Witt"
# defaultBackgroundImage: "images/muir_woods_pano.jpg"

footer:
  showCopyright: true
author:
  name: Mike Witt
  image: images/dog_profile_AI_GEN.png
  headline: Human, often awkward
  bio: Electrical Engineer

homepage:
  homepageImage: "images/muir_woods_pano.jpg"

See the first three paragraphs:
https://gohugo.io/configuration/module/#default-mounts

Thanks. I saw that, but I didn’t understand what the actual implications were. Adding a new mount with source/target as assets seemed to fix it.

I guess I was under the impression that it was a simple dictionary update when configuring the mounts, but it’s really way more complicated than that…

1 Like

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