Can't figure out nested context for page bundle resource

I ran into a problem accessing .Resources inside a context that does not seem to adhere to the context logic as I understand it.

Here is an extract from my list template:

   {{- range (where .Site.Pages "Kind" "section").ByDate.Reverse }}
       {{/* sanity check, lists all image files in that page bundle */}}
       {{ range .Resources  }}
           {{ warnf "album %s sanity check: resource %s" $title . }}
       {{ end }}

       {{ with .Params.albumthumb }}
           {{/* I thought $. gives me the parent context but here my Resource slice is empty */}}
           {{/* What should I do to get the same list as above? */
           {{ range $.Resources  }}
               {{ warnf "album %s second sanity check %s" $title . }}
           {{ end }}
       {{ end }}
   {{ end}}

I think I figured it out. $.Resources refers to the top most context. What I need is the “middle one”.

Now I just save .Resources in a variable before changing context.

   {{- range (where .Site.Pages "Kind" "section").ByDate.Reverse }}
       {{/* sanity check, lists all image files in that page bundle */}}
       {{ range .Resources  }}
           {{ warnf "album %s sanity check: resource %s" $title . }}
       {{ end }}

       {{ $temp_res := .Resources }}
       {{ with .Params.albumthumb }}
           {{/* .Resources is not longer available directly but it was saved in $temp_res */}}
           {{ range $.temp_res  }}
               {{ warnf "album %s second sanity check %s" $title . }}
           {{ end }}
       {{ end }}
   {{ end}}

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