HUGO

.RenderString and render hooks

I’m looking to use .RenderString as I want to make use of render hooks. Markdownify does everything I need except when I want to handle images its not ideal and replaceRE is very useful but only up to a certain point.

I’m not certain but from the documentation I don’t believe I need to do anything additional for it to recognise the render hooks. I don’t need different options from the page.

Any ideas/thoughts will be much appreciated.

{{ .copy | markdownify }}
{{ .copy | $.Page.RenderString }}

Both are producing the exact same output despite the fact that I have a render-image.html file (definitely working tested via .Content) which should convert the image file reference to a <img> tag.

<h2>Sample Title Blah Blah</h2>
![](/uploads/sample-image.jpg)

Exact issue has been discussed here:
https://discourse.gohugo.io/t/render-hooks-not-hooking/23605/8

{{ $c := .Content }}
{{ .copy | $.Page.RenderString }}

Unfortunately this approach of making sure .Content is present on the page doesn’t work for me.

When I download ghandiShepard’s repo I can see the fix working so I will now need to figure out why it works on that site and not mine.

Edit: If I build a quick shell of a new site this works for me but I have no idea why its not working in my current project.

Sorted

I’ll explain in case anyone else encounters this issue.
It turns out that if there is no line break between the ![](/uploads/sample-image.jpg) and any HTML in the string it prevents the render hooks.

Avoid something like this <div class="img-wrapper">![](/uploads/sample-image.jpg)</div>

Massive relief to figure this out as .RenderString is a game changer for me.

Kudos to the gandhiShepard and onedrawingperday