Slice of sections not working

Why is this not working?

{{- $sections := slice "foo" "bar"}}
          {{- if and (ne .Section $sections)}}
<!-- code here excluding sections foo and bar -->
{{- end }}

but this works?

 {{- if and (ne .Section "foo") (ne .Section "bar" )}}
<!-- code here excluding sections foo and bar -->
{{- end }}

So ne does not support slices? I’d rather opt out the few sections than opt in with in.

{{ if not (in (slice 1 2 3) 4) }}
  4 is not in [1 2 3]
{{ end }}

This doesn’t work either.

{{- if (not (in .Section $sections ) )}}

You’ve reversed the arguments.

I am lost. :grin:

{{- if (not (in $sections .Section) )}}
               these were reversed

I’ve never encountered that reversing before. Would you kindly care to explain why this is the case? (I think I had an old instance of if .IsPage (in .Section $sections) that used to work until I rewrote my code to remove it.).

Also, I could not find not in the documentation.

That’s the way it has always been: haystack then needle, not needle then haystack.

So, with a slice, I pass them before the section…noted.

The introduction to templating documentation has this:


The link points to:

The built-in functions, including the logical operators and, or, and not are documented further down the page:

More about the logical operators here.

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