Is string one not in string two?


I am very new to Hugo and have not any experience with Go.
Hugo version v0.14 BuildDate: 2015-05-26T01:29:16+02:00

In my template, I want to test if string one is not in string two:

{{ $haystack := "find needle in haystack" }}
{{ $needle := "needle"}}    
{{ if not in $haystack $needle }}
   {{/* do something */}}
{{ end }}

After insert the code above, hugo build failed. I have get the following error:

ERROR: 2015/06/20 Error while rendering page prueflinge/prueflinge/ template: prueflinge/single.html:54:22: executing "prueflinge/single.html" at <not>: wrong number of args for not: want 1 got 3

Can I only use “not in” in combination with where (see documentation)?

{{ if not (in $haystack $needle) }}

Adding some parens should give you the one argument that not wants.

1 Like

That works.
Thank you for your quick response! :slight_smile: