HUGO

Render Hooks not ... hooking

Hi, I’m processing some text stored in front matter (for a forestry site) using :

{{ $text | $.Page.RenderString }}

which is producing ok HTML but is not pulling the render hook.

Has anyone else had problems?

I’m not entirely sure if this is a recent problem or not or if it is chalked up to some structural issue of my project. I can share the repo with @bep if needed.

You cannot access the Markdown Render Hook from a template, these only work with Markdown syntax for links or images entered in content files.

From both the documentation and experience (and a test that I did on another site – where the render hooks are, for some reason working), this is not the case.

Just like with markdownify, you can apply .RenderString via the .Page (so… .Page.RenderString) to an arbitrary piece of markdown.

Ok, found out about some interesting things:

@bep @onedrawingperday you might be interested in this behavior – let me know if you would like me to make a support ticket.

Seems like a few things : 1) something funky is happening when {{ .Content }} is/isn’t generated 2)caching causing it hard to debug

So I have a template:

<!DOCTYPE html>
<html lang="{{ .Site.Language }}">
  <body>
      {{ "*hello* this is some markdown. ![this is (not) an image](https://gohugo.io/commands/)" | .Page.RenderString }}
      <br>
      {{ ( string .Params.mark ) | .Page.RenderString }}  <= pulling some markdown from frontmatter
  </body>
</html>

which produces :

<!DOCTYPE html>
<html lang="en">
  <body>
      <em>hello</em> this is some markdown. <img src="https://gohugo.io/commands/" alt="this is (not) an image">
      <br>
      <em>hello</em> this is some markdown. <a href="https://gohugo.io/commands/">this is a link</a>
</body>
</html>

ok, no render hooks … looks like it it rendering the markdown “normally”

Now, with this as the template :

<!DOCTYPE html>
<html lang="{{ .Site.Language }}">
  <body>
      {{ "*hello* this is some markdown. ![this is (not) an image](https://gohugo.io/commands/)" | .Page.RenderString }}
      <br>
      {{ ( string .Params.mark ) | .Page.RenderString }}  <= pulling some markdown from frontmatter
      <br>
      {{.Content}}
  </body>
</html>

it generates what is expected (though i think b/c of some caching it only refreshes correctly on the second save) :

<!DOCTYPE html>
<html lang="en">
  <body>
      <em>hello</em> this is some markdown. 
<figure>
  <img src="https://gohugo.io/commands/"
       alt="this is (not) an image"
       style="">

    <figcaption>title</figcaption>

</figure>
      <br>
      <em>hello</em> this is some markdown. <a href="https://gohugo.io/commands/" target="_blank">this is a link</a>
      <br>
</body>
</html>

Strange, no?

NB
I’ve tried this on my larger project which is a Forestry site so everything is within the Front matter. Basically how I handle things is that I parse through the front matter tree and call different partials which render/insert the html. I’ve found that I only have to call {{ $c := $.Page.Content }} at the “lowest level” partial which calls {{ $markdown | $.Page.RenderString }} (where $markdown is some markdown in the frontmatter) to have the render hooks hook.

hey, just wanted to check in to see if others have dealt with this, too.