Single page print image locations

I have a minor issue with a page I’ve created that bundles all the content in the site into a single page (so I can PDF it)

given this structure:

all the content is pulled into the single /_print page, but the image references are wrong.
they all reference /image.png - rather than section/post1/image.png as they need to

is there any workaround for this?

can you share a bit more of the code you have on _print/ ? Or a repository with this site so we can take a look.

At first look I think that what you need might be in this section of the documentation:

I’ve simplified it a bit but this is the code:

{{ range where .Site.Pages "Section" .Section}}
        {{ range .Pages }}
        <section id="main" ">
                      {{ .Content }}
        {{ end }}
{{ end }}

This shows us how you’re creating your print page, but how does each page reference images? Show us that too.

they are just markdown so

as it’s in the same folder

unless I’m missing the question?

by the way, the normal ‘single’ page works fine… it’s just the combined print page that doesn’t (due to the path)

I see. Your image links work in your single pages because the links are relative. But in your print page, you’ll need to make them absolute links. Depends on how your permalinks are setup, but probably something like:


I can’t really do that in the markup because any preview would then break
so the markdown is correct, but I need to include the full path in the print page

I see two potential solutions. Others may see more.

(1) use absolute image paths everywhere (note: this will only break your markdown-text-editor preview, not your hugo server preview)

(2) do some fancy find-n-replace in your print template to find all <img> elements and replace their src attribute with the absolute path

1 Like