contains

Description

Returns whether a list or string contains an item or substring

 boolean contains( mixed haystack , mixed needle )

Returns whether  haystackcontains needle.

  • If haystackis a string, returns trueif needleis a substring.
  • If haystackis a list, returns trueif needleis a member of that list.
  • If haystackis an object, returns trueif needleis a value (not a key) of that object.
  • Otherwise, will return false.

Example

{contains('foobar','ooba') ? 'yes' : 'no'}                   = yes 
{contains('foobar','foobari') ? 'yes' : 'no'}                = no 
{contains(['a','b','c'],'b') ? 'yes' : 'no'}                 = yes 
{contains({"foo":"bar","baz":"bap"},"bar") ? 'yes' : 'no'}   = yes 
{contains({"foo":"bar","baz":"bap"},"foo") ? 'yes' : 'no'}   = no

Check if a subscriber is a member of a list, using the Profile object:

{contains(profile.lists,"Main")}

Check if a user has opted out of a specific template by referencing the Public Name:

{contains(profile.optout_templates,"Notifications")}
Top