Only feature that i miss is to be able to write own pieces of code (like partials) that would return value.
It would get variable (slice, map, string, integer, bool, …) and return something.
Now i have too heavy layouts (20 lines of code) where i’m using ranges and appends to build one single variable which is than used to output 4 lines of html. In other template I have same 20 lines of code to produce very same variable which is than used to output different html.
So i’m repeating myself over and over in many layouts to achieve the same.
Desired solution:
{{ $description := .Page | customdescription }}
Here is real working example:
{{ $description := slice -}}
{{- if .Description -}}
{{- $description = $description | append (.Description | markdownify | plainify) -}}
{{- else if .Content -}}
{{- $description = $description | append (.Content | plainify) -}}
{{- else if .Params.blocks -}}
{{- range .Params.blocks -}}
{{- range $key,$item := . -}}
{{- if or (eq $key “text”) (eq $key “title”) -}}
{{- $description = $description | append ($item | markdownify | plainify) -}}
{{- end -}}
{{- if (eq $key "items") -}}
{{- range $item -}}
{{- range $key2,$item2 := . -}}
{{- if or (eq $key2 "text") (eq $key2 "title") -}}
{{- $description = $description | append ($item2 | markdownify | plainify) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $description = (replaceRE "\\n+|\\ \\;" " " (delimit $description "; ")) | default .Site.Params.description | truncate 200 -}}