HUGO

Crossposting images - Markdown Render Hooks

Often I find myself having to crosspost an image from another content file. In the past I used shortcodes or symlinks to achieve this. However now with the new Markdown Render Hooks image crossposting is even simpler.

Markdown Image Syntax

![Some text](image.jpg "/post/lorem/index.md")

Contents of render-image.html

{{ if strings.Contains .Title ".md" }}
{{ with $.Page.GetPage .Title }}
<--- crossposted image template --->
{{ end }}
{{ else }}
<--- normal render-image template --->
{{ end }}

In the above the title attribute is checked and if it contains the string .md first .GetPage is used to fetch that page and then the specified image is rendered.

3 Likes