# Render image hook and leaf bundles

**URL:** <https://discourse.gohugo.io/t/render-image-hook-and-leaf-bundles/35896>\
**Category:** support\
**Created:** [December 4, 2021, 4:10am UTC](https://discourse.gohugo.io/t/render-image-hook-and-leaf-bundles/35896 "2021-12-04T04:10:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roger](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/roger/32/14113_2.png) [@Roger](https://discourse.gohugo.io/u/Roger)\
**Post date:** [December 4, 2021, 4:10am UTC](https://discourse.gohugo.io/t/render-image-hook-and-leaf-bundles/35896/1 "2021-12-04T04:10:15Z")

</div>

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](https://yyz2.discourse-cdn.com/flex036/image/image.jpg)

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.

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [December 4, 2021, 7:32am UTC](https://discourse.gohugo.io/t/render-image-hook-and-leaf-bundles/35896/2 "2021-12-04T07:32:57Z")

</div>

> [@Roger](#):
>
> resources.Get .src

[`resources.Get`](https://gohugo.io/hugo-pipes/introduction/#from-file-to-resource) 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`](https://gohugo.io/content-management/page-resources/#methods) 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](https://gohugo.io/getting-started/configuration-markup/#markdown-render-hooks) 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](https://discourse.gohugo.io/t/simple-image-render-hook-template-for-responsive-images/22464) since it provides a more advanced example for rendering responsive images with Markdown Render Hooks.

---

<div class="post-metadata">

**Author:** ![Roger](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/roger/32/14113_2.png) [@Roger](https://discourse.gohugo.io/u/Roger)\
**Post date:** [December 4, 2021, 6:52pm UTC](https://discourse.gohugo.io/t/render-image-hook-and-leaf-bundles/35896/3 "2021-12-04T18:52:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [December 4, 2021, 8:39pm UTC](https://discourse.gohugo.io/t/render-image-hook-and-leaf-bundles/35896/4 "2021-12-04T20:39:11Z")

</div>

> [@Roger](#):
>
> meaning it must search relative to the Page Resource, no?

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

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [December 6, 2021, 8:39pm UTC](https://discourse.gohugo.io/t/render-image-hook-and-leaf-bundles/35896/5 "2021-12-06T20:39:25Z")

</div>

Closed on December 6, 2021, 8:39pm UTC

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