- If .IsPage - in partial file

I resize post images for post and list pages using this partial:

{{ partial "imgoptim.html" . }}
{{- $src := .Page.Resources.GetMatch .Params.image }}
{{- $alt := .Params.title }}
{{- with $src }}
<img srcset='
{{- if ge .Width "300" -}}
  {{ (.Resize "300x").RelPermalink }} 300w,
{{ end }}
{{- if ge .Width "600" -}}
  {{ (.Resize "600x").RelPermalink }} 600w,
{{ end }}
{{- if ge .Width "1200" -}}
  {{ (.Resize "1200x").RelPermalink }} 1200w{{ end }}' sizes="(max-width:480px) 300px, (max-width:768px) 600px, 1200px" src="{{ .RelPermalink }}" loading="lazy" alt="{{ $alt }}">
{{ end }}

I would like to pass .IsPage to use loading=“lazy” on list pages only. Without it, I will create another partial or put the code inside post and list templates.

You already have the page object, so no need to pass anything else:

{{ $src := .Resources.GetMatch .Params.image }}
{{ $alt := .Params.title }}
{{ $isPage := .IsPage }}

No, I wanted to pass true/false .IsPage where this partial is used. This one doesn’t work.

{{ $isPage := .IsPage }}