Render image hook and leaf bundles

If I have a directory:

content/news/04-04/

and within this directory I have:

index.md
/image/image.jpg

within the markdown I have

what a great image

And I want to hijack the image render hook and within that image render hook do something:

{{ $imageresource := resources.Get .src }}
*.src being in this case “/image/image.jpg”

I get nothing.

I’ve tried every permutation of resources.Get I can think of - GetMatch/.Resources.Get/.Resources.GetMatch/.Page.Resources.GetMatch, on and on to infinity.

Now, the above resources.Get works PERFECTLY if the image in quest in is assets.

I’ve research out this in the various links and supports etc.

It’s possible I’m just very slow. However, can someone clarify how to get a leafbundle image asset from within the image render hook so that it can be used with Image Processing?

As always, thank you very much for everyone’s time. Please pardon the possible stupidity of this question.

resources.Get is a method which takes one argument: the filepath of the file relative to the asset directory and it does not apply to leaf bundles (unless you map the content directory as the assets directory).

GetMatch is a method to get page resources, it is the same as Match but it will return the first match.

The variable for a Markdown image ruled by a Markdown Render Hook Template is not called .src but .Destination, see the doc for reference.

Therefore I think that the above construct should be rewritten to something like:
.Page.Resources.GetMatch .Destination

Also have a look at this topic since it provides a more advanced example for rendering responsive images with Markdown Render Hooks.

2 Likes

Thank you for your fast replay.

Your explanation and it’s simplicity really helped me a lot.
(So, knowing that I didn’t supply the repo in question, their was a convoluted aspect to this.)

1st. Understood on .src and destination etc. In this case .src was providing the URL Path for reasons.
2nd. Now knowing that GetMatch should work, you made a statement “it is the same as Match but it will return the first Match” - meaning it must search relative to the Page Resource, no?

I was approaching the .Page.Resources from within a range statement, which I didn’t realize changes the page context… Which is important for what I was doing as, it should have been obvious to me, to get a image relative to a leaf bundle the page context would be important…

So, thank you very much! This totally resolved it for me and I learned a fair bit.

Yes. The method looks among the group of Page Resources that exist in a Bundle.

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