{{/* GetHeaderImage This partial gets the resource for the header image for a given page. If a header_image was set in the page's front matter, then that will be used. If not set, this will search page resources to find an image that contains the word "cover", and if found, returns the path to that resource. If no header_image was set, and there's no "cover" image in page resources, then this partial returns an empty string (which evaluates to false). @return Resource of header image, or an empty string if not found. */}} {{ $headerImage := "" }} {{/* Defined as params */}} {{ if isset .context.Params .name }} {{/* param exist and is not zero */}} {{ if .context.Param .name }} {{ with .context.Resources.GetMatch ( .context.Param .name ) }} {{ $headerImage = . }} {{ end }} {{ end }} {{ end }} {{/* Defined as resource */}} {{ if $headerImage }} {{ else }} {{ if .context.Resources.GetMatch .name }} {{ $img := .context.Resources.GetMatch .name }} {{ with $img }} {{ $headerImage = . }} {{ end }} {{/* Find the first image with 'cover' in the name in this page bundle. */}} {{ else }} {{ $img := (.context.Resources.ByType "image").GetMatch "*cover*" }} {{ with $img }} {{ $headerImage = . }} {{ end }} {{ end }} {{ end }} {{/* return either a Resource, or an empty string. Note that partials can only have a single return statement, so this needs to be at the end of the partial (and not in the if block) */}} {{ return $headerImage }}