In an email script/Velocity, what's the best way to anti-match a single value against a list of values in an if clause with several conditions?
For example: I could do
#set( $country = 'United States' ) #set( $list = ['United States','United Kingdom'] ) #if( !$list.contains($country) && 1 == 1 ) Salve, #else Dear friend, #end
#set( $country = 'Italy' ) #if( !$country.matches('^(United States|United Kingdom)$') && 1 == 1 ) Salve, #else Dear friend, #end
However, I am looking for a more direct and faster way in the veins of
#if( !['United States','United Kingdom'].contains($country) && 1 == 1 )
or something similar.
As I came across this question a few times already, I thought I'd ask.
Solved! Go to Solution.
The 1st method is preferred. If you’re desperate for a one-liner you can do
#if( !$display.alt(["United States","United Kingdom"]).contains($country) )
but it’s best avoided because that extra wrapper ends up losing clarity IMO.