Arif
May 31, 2023, 10:14pm
1
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 }}
Arif
May 31, 2023, 10:46pm
3
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 }}
Arif
May 31, 2023, 11:15pm
5
This doesn’t work either.
{{- if (not (in .Section $sections ) )}}
You’ve reversed the arguments.
{{- if (not (in $sections .Section) )}}
------------------
these were reversed
Arif
May 31, 2023, 11:41pm
9
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.
Arif
May 31, 2023, 11:45pm
11
So, with a slice, I pass them before the section…noted.
The introduction to templating documentation has this:
The link points to:
https://pkg.go.dev/text/template
The built-in functions, including the logical operators and
, or
, and not
are documented further down the page:
https://pkg.go.dev/text/template#hdr-Functions
More about the logical operators here .
system
Closed
June 2, 2023, 11:50pm
13
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.