Velocity: Match value against list of values | Community
Skip to main content
New Participant
January 26, 2022
Solved

Velocity: Match value against list of values

  • January 26, 2022
  • 1 reply
  • 1376 views

Hi community,

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

 

or

 

#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.

Thank you.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

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.

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
January 26, 2022

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.