gallery.html 1.4 KB

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