Use the "iffield" command in situations where you simply want to know whether a field is equal to a certain value or not.
The "iffield" syntax is:
%%
iffield tablename.fieldname
value1 "content1"
value2 "content2"
...
valuex "contentx"
"defaultcontent"
%%
Here is what it's doing: for each individual recipient, the command looks in the table tablenamefor the field fieldname. If the field is equal to value1, then the command prints content1 and ends the script. If the field is equal to value2, then the script prints content2, and so on. (You can have as many value/content pairs as you like -- but make sure each value has a content result.) If the field is not equal to any of the values, the script prints defaultcontent.
This command is perfect for simple true/false conditional content:
%% iffield tablename.fieldname value "contentif-true" "content-if-false" %%
Since paragraphs don't matter outside the curly brackets, you can put everything on one line!
Example 1
Say you sell pet supplies, and are having a special on dog bowls. You want to tell only dog owners about the special -- owners of any other pet should not see anything.
You already have a text field called pet in the members_ table. The field describes what type of pet the recipient has.
%%
iffield
members_.pet dog
"We're having a special on dog
bowls!"
"
"
%%
Bob, who owns a dog, would see:
We're having a special on dog bowls!
Mary, who owns a cat, would not see anything, since the default text is blank (that is, there is nothing between the final set of quotes).
To save space, you can write the entire command on one line. If the defaultcontent is blank, you can even omit it. The following command would work just the same as the one above:
%% iffield members_.pet dog "We're having a special on dog bowls!" %%
Example 2
Say you've opened two new stores in San Francisco and Denver. You want to tell all Californians about the San Francisco store, and all residents of Colorado about the Denver store. Since residents of other states won't be interested, you don't want to tell them about these specific stores.
You already have a field called state in the members_ table. This field contains two-letter designations for US states.
%%
iffield members_.state
CA "Come see our new store in San Francisco!"
CO "Come see our new store in Boulder!"
"We're opening new stores all the time!"
%%
Bob, who lives in California, would see:
Come see our new store in San Francisco!
Joe, a resident of Colorado, would see:
Come see our new store in Denver!
Mary, a Connecticut resident, would see the default text:
We're opening new stores all the time!
NOTE When you paste examples into content or mailings while the HTML Editor is enabled, extra HTML tags are added. We recommend that you disable the HTML Editor before pasting example code.