Updated image render hook



Reading time: 1 minute

I have updated the image render hook from my article Resize all images. It now checks for SVG images and handles them correctly. Additionally, I use with to check for the existence of the image resource.

{{ with (resources.GetMatch .Destination) }}
    {{ if ne .MediaType.SubType "svg" }}
        <img src="{{ (.Resize `900x jpg Smart q50`).RelPermalink | safeURL }}" alt="{{ $.Text }}" />
    {{ else }}
        <img src="{{ .RelPermalink | safeURL }}" alt="{{ $.Text }}" />
    {{ end }}
{{ end }}
Fenix & Joost