If you have a contact associated with a custom field that saves their gender as a string, you can use the liquid script to check the gender and print the content that you would want them to receive, according to their gender.

Go through the script below and remember to modify the script according to your preferences.


Script:


{% assign x=contact.gender %}

{% if x==M %}

The gender is Male

{% elseif x==F %}

The gender is Female

{% else %}

The gender is Unknown

{% endif %}


Method:


  • First, assign the value present in the gender custom field to a variable. Here, the variable x is being used to save the values present in the custom field “contact.gender”
  • Next, we will check if the value of the variable x is equal to “M” (or the value that you saved for a specific gender)
  • In this example M=Male, so we print the string “The gender is Male”
  • Since we are using the ELSE/IF condition here. If the first condition fails, the script will check the second condition.
  • In the second condition, we compare and determine if the value of the variable x is equal to “F” where "F" represents female.
  • If yes, we print the value “The gender is Female”
  • Next, if both of the above conditions fail, we print the value “The gender is unknown” or any other chosen value.
  • ‘End IF’ is used to close the else/if condition.