Add ability to have a fallback image if the primary no longer exists.

This commit is contained in:
2025-11-19 20:02:17 -07:00
parent 04eab8ff39
commit 15850d3c92

View File

@@ -0,0 +1,17 @@
{{ $url1 := .Get "img1" | default (.Get "url") | default (.Get 0)
}}{{ $url2 := .Get "img2" | default (.Get "fallback") | default (.Get 1)
}}{{ $alt := .Get "alt" | default (.Get 2)
}}
<!-- These do not seem to work. Using JS solution.
<picture>
<source srcset="{{ $url1 }}">
<img src="{{ $url2 }}" alt="{{ $alt }}">
</picture>
<picture>
<source media="(min-width: 1px)" srcset="{{ $url1 }}">
<img src="{{ $url2 }}" alt="{{ $alt }}">
</picture>
-->
<img src="{{ $url1 }}" alt="{{ $alt }}" onerror="this.onerror=null; this.src='{{ $url2 }}';">