7
1
mirror of https://gitlab.com/ansol/web-ansol.org.git synced 2024-11-22 06:11:30 +00:00
web-ansol.org/themes/academic/layouts/partials/functions/get_address.html
2020-06-11 12:46:16 +01:00

22 lines
1.5 KiB
HTML

{{/* Function to return a formatted address given a semantic address. */}}
{{/* Check for valid site config. */}}
{{ if not site.Params.address_format }}{{errorf "Address format missing from `params.toml`!"}}{{end}}
{{ if not site.Params.address_formats }}{{errorf "Address formats missing from `params.toml`!"}}{{end}}
{{ $page := . }}
{{ $address := .address }}
{{ $format_name := $page.Params.address_format | default site.Params.address_format | default "en-us" }}
{{ $format := index site.Params.address_formats $format_name }}
{{ $address_display := slice }}
{{ range $k, $v := $format.order }}
{{ if eq $v "street" | and $address.street }}{{$address_display = $address_display | append $address.street | append (index $format.delimiters $k | default "") }}{{end}}
{{ if eq $v "city" | and $address.city }}{{$address_display = $address_display | append $address.city | append (index $format.delimiters $k | default "") }}{{end}}
{{ if eq $v "region" | and $address.region }}{{$address_display = $address_display | append $address.region | append (index $format.delimiters $k | default "") }}{{end}}
{{ if eq $v "postcode" | and $address.postcode }}{{$address_display = $address_display | append $address.postcode | append (index $format.delimiters $k | default "") }}{{end}}
{{ if eq $v "country" | and $address.country }}{{$address_display = $address_display | append $address.country | append (index $format.delimiters $k | default "") }}{{end}}
{{end}}
{{ return (delimit $address_display "") }}