{{ define "current" }}{{ printf "$%.2f" . }}{{ end -}} {{ define "basicProduct" -}} Name: {{ .Name }}, Category: {{ .Category }}, Price: {{- template "current" .Price }} {{- end -}} {{ define "expensiveProduct" -}} Expensive Product: {{ .Name }}({{ template "current" .Price }}) {{- end -}} {{ define "mainTemplate" -}}

There area {{ len . }} products in the source data .

First product is {{ index . 0 }}

{{ range . -}} {{ if lt .Price 100.00 -}} {{ template "basicProduct" . }} {{ else if gt .Price 1500.00 -}} {{ template "expensiveProduct" . }} {{ else -}}

Midrange Product: {{ .Name }}({{ template "current" .Price }})

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