Bundled images, range, and context

#1

Imagine having a sidebar that lists posts from a specific section on a single article view. Within the single.html template, I’ve added a range, iterating content pieces from that specific section:

{{ range where .Site.Pages "Section" "sidebar" }}
	{{ .Content }}
{{ end }}

The sidebar content contains (bundled) images - example: ![](shark_pic.jpg) And the problem is those images get the wrong path. Their URL ends up being relative to the ‘parent’ single page url, and not relative to the page they’re bundled with.

Do you happen to have any tips for me? Thanks!

#2

The problem statement is not clear to me. You’ll need to share a repo with a minimal site showing your problem (in case you cannot share the whole site).

#3

Sorry, not a Github user so here’s an example:

Say I’ve opened http://mysite.com/articles/how-to-raise-chickens/. Beside the main content, there is a sidebar, displaying posts from a different section. The sidebar posts contain (page-bundled) images. I’ve added those images in the Markdown files by using just their file names, as they’re bundled and Hugo should get their full path as relative to the sidebar post url - something like http://mysite.com/sidebar/flying-pigs/pig_1.jpg.

Instead of that though, the images get a path, relative to the main content (the chicken-related article) - http://mysite.com/articles/how-to-raise-chickens/pig_1.jpg.

#4

Sorry @frangipani, we really need a test repo to reproduce your issue. Please read Requesting Help.

Your issue is definitely somewhere in a template, with the URL rendering. I suggest you make a new project, very simple, and try to get only that sidebar working. That often helps folks figure out their issue. :slight_smile:

#5

Also, to add to what @maiki said, you don’t have to be a GitHub user to provide good reproducible examples.

Recommended: Use a git repo (git is not the same as GitHub), and host it on anywhere (GitHub, GitLab, Bitbucket, Savannah, your own git repo instances using Gitea, Gogs, etc.)

Not recommended (at least by me) – But still possible to share your example site: Create a .zip/.tar.gz/.tar.xz and share it via Dropbox/Google Drive/OneDrive/your own hosting solution.

1 Like
#6

Here’s a repo: https://github.com/30G/bundlery

Please be aware this is the 3rd time I use Git so…

Thanks again!