. context range index

In my case, this code only works when ranging without $index, not with $index

Range:

[
{{- range $index, $page := (where .Site.RegularPages "Type" "in" (slice "type_a" "type_o" "type_ab" )) -}}
    {{- if gt $index 0 -}} , {{- end -}}

  1. In the following, given .Site.Params.default is set, {{ partial “debugprint” . }} lists data, indicating matches.
{{- with .Site.Params.default -}}
{{- $match := . -}}
{{- with $.Site.GetPage "section" "headless" -}}
{{- with .Resources.GetMatch $match -}}

 {{ partial "debugprint" . }}

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

  1. Next, given .Params.featureImage is set for any .Site.RegularPages, {{ partial “debugprint” . }} lists data, indicating matches.

{{- with .Params.featureImage -}}
{{- $match := . -}}
{{- with $.Site.GetPage "section" "headless" -}}
{{- with .Resources.GetMatch $match -}}

{{ partial "debugprint" . }}


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


  1. Next, although .Params.featureImage is set for any .Site.RegularPages, {{ partial “debugprint” . }} does not list data, indicating no matches.

{{- with .Params.featureImage -}}
{{- $match := . -}}
{{- with $.Page.Resources.GetMatch $match -}}

{{ partial "debugprint" . }}

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

Close Range:


{{- end -}}
]

What is the correct . syntax for: {{- with $.Page.Resources.GetMatch $match -}} to get page bundle matches in 3 ?

Thanks everyone for your productivity (especially, it seems, Bep)

Solution:

{{- with $page.Params.featureImage -}}
{{- $match := . -}}
{{- with $page.Resources.GetMatch $match -}}

{{ partial "debugprint" . }}

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

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.