{{- /* This partial requires input context to have a Scratch with "content" $.Scratch.Get "content" must return a slice (array) of object maps Those objects need a "type" key, which can be "link" or something else. See below to see what needs to be in those different types */}}
{{- $column_count := default 2 ($.Param "column_count") }} {{- $downloadable := default true ($.Param "images_downloadable") }} {{- $orig_download := default false ($.Param "images_downloadable_use_orig") }} {{- /* Initialize the column storage */}} {{- range $column_ind := seq $column_count }} {{- $st_name := printf "col-%d" $column_ind }} {{- $st_height_name := printf "col-height-%d" $column_ind }} {{- $.Scratch.Set $st_name (slice) }} {{- $.Scratch.Set $st_height_name 0 }} {{- end }} {{- /* Add the sections into the columns followed by images */}} {{- range $elem_index, $elem_val := $.Scratch.Get "content" }} {{- /* Find the least-filled column */}} {{- $.Scratch.Set "min_height" -1 }} {{- $.Scratch.Set "min_col" -1 }} {{- range $column_ind := seq $column_count }} {{- $st_height_name := printf "col-height-%d" $column_ind }} {{- $col_height := $.Scratch.Get $st_height_name }} {{- $min_height := $.Scratch.Get "min_height" }} {{- if (or (eq $min_height -1) (lt $col_height $min_height)) }} {{- $.Scratch.Set "min_height" $col_height }} {{- $.Scratch.Set "min_col" $column_ind }} {{- end }} {{- end }} {{- /* column_ind becomes the least-filled column */}} {{- $column_ind := $.Scratch.Get "min_col" }} {{- if eq $column_ind -1 }} {{- errorf (printf "When processing '%s', failed to find a least-filled column!" $.Page.File.Path) }} {{- end }} {{- $st_name := printf "col-%d" $column_ind }} {{- $st_height_name := printf "col-height-%d" $column_ind }} {{- /* Create a new version of the elem_val with an index reflecting position now, well after sorting is complete, and as we're placing things */}} {{- $reind_val := merge $elem_val (dict "index" $elem_index) }} {{- $column := $.Scratch.Get $st_name }} {{- $column := $column | append $reind_val }} {{- $.Scratch.Set $st_name $column }} {{- $.Scratch.Set $st_height_name (add ($.Scratch.Get $st_height_name) $reind_val.thumb.Height) }} {{- end }} {{- /* Output the images in columns */}} {{- range $column_ind := seq $column_count }} {{- $st_name := printf "col-%d" $column_ind }} {{- $column := $.Scratch.Get $st_name }}
{{- range $column }} {{- $filename := path.Base .image.Name }}
{{- if (eq .type "link") }} {{ .title }}

{{ .title }}

{{- else }} {{ . }} {{- if (default false ($.Param "taxonomies_links")) }}
{{- range $taxname, $terms := .taxonomies }} {{- range $terms }}
{{- $url := ( printf "/%s/#%s" ($taxname | urlize) ( . | urlize ) ) | relURL }} {{ . | humanize }}
{{- end }} {{- end }}
{{- end }}

{{ .phototitle }}

{{- end }}
{{- end }}
{{- end }}