How to tell Hugo to exclude listing pages from section condition?

Hi there,

In the below Hugo code that I use

# layouts/partials/js.html
{{ $indexJS := resources.Get "js/site.js" }}

{{ $listingJS := resources.Get "js/listing.js" }}

{{ if or (eq .Section "properties-for-sale") (eq .Section "properties-to-rent") }}

{{/* custom js for listing pages */}}

{{- if .Site.IsServer }}

{{ $indexJS := resources.Get "js/site.js" }}

{{ $listingJS := resources.Get "js/listing.js" }}

{{- else }}

{{ $indexJS := resources.Get "js/site.js" | minify }}

{{ $listingJS := resources.Get "js/listing.js" | minify }}

{{- end }}

{{ $js := slice $indexJS $listingJS | resources.Concat "js/listing.js" }}

<script defer async src="{{ $js.RelPermalink | absURL }}" integrity="{{ $js.Data.Integrity }}"></script>

{{ else }}

{{- if .Site.IsServer }}

{{ $indexJS := resources.Get "js/site.js" }}

{{- else }}

{{ $indexJS := resources.Get "js/site.js" | minify }}

{{- end }}

<script defer async src="{{ $indexJS.RelPermalink | absURL }}" integrity="{{ $indexJS.Data.Integrity }}"></script>

{{ end }}

Hugo output the wrong js file for me

# Hugo project structure 
content
├── archetypes
├── assets
├── config
├── content
│   └── properties-for-sale 
│       ├── list.md # here I want the `js/site.js`
│       └── regular-page.md # here I want the `js/listing.js`
├── data
├── layouts
├── resources
├── static
└── themes

What is wrong with my code? How can I exclude list pages from the condition of {{ if or (eq .Section "properties-for-sale") (eq .Section "properties-to-rent") }}

Thanks

Ok Fixed by using

{{ if and (or (eq .Section "properties-for-sale") (eq .Section "properties-to-rent")) .IsPage }}

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