jtbx
e4ff96aee2
If a page is not a page bundle, it can't access files in the same directory via the .Resources variable. So we need to detect this condition and get the image file in another way.
20 lines
665 B
HTML
20 lines
665 B
HTML
{{- $imagename := (.Get 0) }}
|
|
{{- $options := .Get 1 }}
|
|
{{- $classes := .Get 2 | default "" }}
|
|
{{- $link := .Get 3 | default "" }}
|
|
{{- $isBundle := ne .Page.BundleType "" }}
|
|
|
|
{{- $page := .Page }}
|
|
{{- if not $isBundle }}
|
|
{{ $page_dir := path.Dir .Page.File }}
|
|
{{ $pagebundle_path := path.Join "/" $page_dir }}
|
|
{{ $page = .Site.GetPage $pagebundle_path }}
|
|
{{- end -}}
|
|
|
|
{{- with $page.Resources.Get $imagename }}
|
|
{{- with .Resize $options -}}
|
|
{{ if $link }}<a href="{{ $link }}">{{ end }}
|
|
<img src="{{ .RelPermalink }}" class="md-img {{ $classes }}" width="{{ .Width }}" height="{{ .Height }}">
|
|
{{ if $link }}</a>{{ end }}
|
|
{{- end }}
|
|
{{- end }}
|