The IF function allows you to perform conditional processing (not to be confused with the IIF function which is a simplified version).
The IF function can be written with the following statements:
- IF – (required) – Begin the IF conditionals with this statement
- ELSEIF – (optional) – You can use the ELSEIF statement for conditional “else if” processing. Multiple ELSEIF statements can be used.
- ELSE – (optional, can only be used once) – If all other statements are not satisfied, default to this else conditional
- ENDIF – (required) – All IF conditionals need to end with the ENDIF statement.
Using just the ELSE conditional statement:
%%[ set @test = “abc” IF @test == “abc” THEN set @response = “Hello, world!” ELSE set @response = “Goodbye” ENDIF ]%% %%=v(@response)=%%
Using ELSEIF statements:
%%[ set @test = “abc” IF @test == “123” THEN set @response = “Hello, world!” ELSEIF @test == “abc” THEN set @response = “Goodbye!” ENDIF ]%% %%=v(@response)=%%
Using IF conditional statements allows the statements to be evaluated depending on what is within the statements. Multiple ELSEIF statements can be used within the conditional statement. Must be opened with IF and closed with ENDIF.