gallery.html 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. {{ $album := "gallery" }}
  2. {{ with .Get "album" }}{{ $album = . }}{{ end }}
  3. <div class="gallery">
  4. {{/* Attempt to automatically load gallery images from page bundle */}}
  5. {{ $images := ($.Page.Resources.ByType "image").Match (printf "%s/*" $album) }}
  6. {{ with $images }}
  7. {{ range $images }}
  8. {{ $image := .Resize "x190" }}
  9. {{/* Check if the user set a caption for this image */}}
  10. {{ $filename := .Name }}
  11. {{ $caption := "" }}
  12. {{ if $.Page.Params.gallery_item }}
  13. {{ range (where $.Page.Params.gallery_item "album" $album) }}
  14. {{if eq (printf "%s/%s" $album .image) $filename}}{{ with .caption }}{{ $caption = . }}{{end}}{{end}}
  15. {{ end }}
  16. {{ end }}
  17. <a data-fancybox="gallery-{{$album}}" href="{{ .RelPermalink }}" {{ with $caption }}data-caption="{{.}}"{{ end }}>
  18. <img src="{{ $image.RelPermalink }}" alt="">
  19. </a>
  20. {{end}}
  21. {{else}}
  22. {{/* Load gallery images from the `static/img/` media library or internet */}}
  23. {{ range (where $.Page.Params.gallery_item "album" $album) }}
  24. {{/* Set image path. */}}
  25. {{ $.Scratch.Set "src" .image }}
  26. {{ if gt (len .image) 4 }}
  27. {{ if ne "http" (slicestr .image 0 4) }}
  28. {{ $.Scratch.Set "src" (printf "img/%s" .image | relURL) }}
  29. {{ end }}
  30. {{ end }}
  31. <a data-fancybox="gallery{{ with .album }}-{{.}}{{ end }}" {{ with .caption }}data-caption="{{.}}"{{ end }} href="{{$.Scratch.Get "src"}}">
  32. <img src="{{$.Scratch.Get "src"}}" alt="">
  33. </a>
  34. {{ end }}
  35. {{end}}
  36. </div>