The link docs show that ref is useful for linking from one document to another using a path, e.g.,
{{< ref "/post/topic/slug" >}}
It doesn’t seem to support other files in a page bundle. For example:
![]({{% ref "/post/topic/slug/summit.jpeg" %}})
This shortcode emits the error:
REF_NOT_FOUND: Ref "/post/topic/slug/summit.jpeg": "/Users/david/dev/blog/content/post/topic/other-post.md:17:5": page not found
Is there something like ref (and urls.Ref for functions) that supports files other than the main document file? Or am I just missing something in my use of ref?
Not to my knowledge, no. I first encounter the issue trying to use urls.Ref in a shortcode, but found the same thing just putting a line like the above directly into a post.
I’m on v0.123.2. Setting those configs made no difference. But those docs refer to files in the assets directory. I’m trying to link to files in a page bundle, which is in the content directory.
Are you trying to access a page resource associated with PAGE-A from PAGE-B? If yes, don’t go down that path. If it’s used in two or more places make it a global asset.
The render hooks work great for that.
If, for some reason, you don’t want to create it as a global asset, you can combine the relref shortcode with an image path relative to source page.
Here are multiple examples:
git clone --single-branch -b hugo-forum-topic-48656 https://github.com/jmooring/hugo-testing hugo-forum-topic-48656
cd hugo-forum-topic-48656
hugo server
Yes, sorry, I thought the error message made that clear, but I should have been more explicit. I could move the image to a global asset directory. It just seems al little silly, though, since I published PAGE-A last week, and now just wanted to point to the same image in PAGE-A’s directory from a new post today, PAGE-B.
But I think I see now, I can try passing the other page as a a reference to my shortcode. This works:
![]({{% ref "/post/topic/slug" %}}summit.jpeg)
To use urls.Ref I just need to look up the other page bundle (using GetPage).
That’s fair, all about tradeoffs. I don’t make any of these sorts of changes to my posts. Agree it’s safer to use a global asset, and less fussy certainly.