Conditional HTML Blocks and Field Blocks
Conditional HTML Blocks and Field Blocks allows for a dynamic process based on one's objectives and priorities. Without this, the process is 'static' and is thus limited to more generic messaging and data collection that is less effective than tailored messaging and data collection.
Condition Expressions
Conditions are written using TALES expressions - a standard high level expression syntax. To accommodate some of the requirements for setting conditions on, some additional variables have been added for use in the eCampaigning Tool that make it more explicit where to check the condition:
- portal: the Plone site in which the [Campaign Action]? exists
- action: the [Campaign Action]? in which the [Action Edition]? exists
- edition: the [Action Edition]? in which Action Steps exists
- request: the HTTP request variables of the visitor
- session: the session variables of the visitor (including from the custom data merge script).
- record: the [Action Record]? of the participant who has just submitted one of an [Action Edition]?'s Action Steps
- here: the first occurrence of an object (e.g. script) in the Zope acquisition path
| Note: | All conditional expressions are case sensitive. The case of the field names in the schema (or wherever else they appear) must match the case used in the expression. |
|---|
Condition Instructions
Because these are TALES expressions, a HTML Block or Field Block with a condition will only display if the condition results in a true statement. This means to test if something is not true you will need to precede the condition with 'not:' so that it is true when it the expression is 'not true' (isn't logic great!)
There are two types of conditions possible:
- boolean: conditions which check if something is true or not
- matching: conditions which compare the values (e.g. x > 5)
Boolean conditions can be written in TALES syntax (e.g. record/receive_updates) while matching conditions can only be written in Python syntax (e.g. python: record.receive_updates == True). Note that in Python, to test if something is equal to something thing else, two equal signs are needed (==). The other operators are as normal:
Comparison Operators:
- Equals: ==
- Less than: <
- Greater than: >
- Greater than or equal to: >=
- Less than or equal to: <=
- Not equal to: != or <>
- Checks to see if an item is in a sequence (e.g. [1,2,3]?): in
- Checks to see if an item is not in a sequence (e.g. [1,2,3]?: not in
Logical operators:
- Require two (or more) values or comparisons: and
- Require one of two (or more) values: or
- Require a value is the inverse: not
If you write conditions others would find useful, please add them below for those who have less experience of writing conditions.
Opt-in Test (boolean)
If you wanted to check the value of the receive_updates field where participants indicate if they want to received updates (opt-in) or not, your condition would either be:
- Opted-in: record/receive_updates
- Did not opt-in: not:record/receive_updates
Condition Examples
- Test of edition record count is less than or equal to goal: edition.getRecordCount() <= edition.getOnsite_edition_goal()
Usage Ideas
Conditional display of Field Blocks and HTML Blocks can be used for a wide range of purposes. Some of the examples below are not yet possible due to the lack of other components like a centralised participant profile system.
Opt-in choice - based
- Displaying the opt-in field (field block) and associated text (html block) only if the person didn't opt-in on the first step (boolean test)
- Used in conjunction with (1) - displaying some thanks text related to opt-ins in (html block) only if the person did opt-in. (boolean test)
- For those who opt-in, identifying users using email address from popular email providers (Hotmail, Yahoo, AOL) and presenting specific instructions in the thank-you text for how to add the campaign email address to their 'whitelist'. This scenario uses text processing (extract just domain name) and multiple conditions (optin=yes and domain= one of x, y, z) (boolean test with custom script(s))
Origin tracking information - based
- Not displaying the opt-in field for existing supporters since they are already opted-in.
- Displaying a extra 'origin' field (field block) and associated text (html block) on the first step like 'where did you find out about this action' if no origin tracking information is picked up (boolean test)
- Displaying different html blocks in the 'headers' and 'footers' depending on a visitor's origin (e.g. imagery to match a particular advertisement so people feel it is part of the same 'flow' without having to create different editions for each advertisement) (matching test)
- Displaying different opt-ins and opt-in statement (=field description) based on the referrer URL or query string variable values. To support coalitions using a central action with the data distributed based on origin after the action. (matching test with custom script(s))
Syntax: use 'session[name-of-variable]?' to fetch the desired tracking variable:
Address country - based
- Displaying different thank-you page / email text based on the country selected or the tracking variables. (matching test)
- Display a different message and thank-you page/email text based on what country they indicate they are from. (matching test)
Time-based
- Display different message and thank-you page/email text based on what date-time they have completed the action on (e.g. before or after a big event/moment). (matching test with custom script(s))
Profile-based
- Displaying another Edition of a Campaign Action that a user hasn't already completed (likely in conjunction with a script to identify what actions they have and haven't taken) (boolean test, needs profile system)
Other related uses
- Skip a step entirely (e.g. address collection) if they are determined to have already provided their address details. (different scope, needs profile system)
Implementation
- Simple boolean tests can be achieved using TALES and matching expressions are only possible with TALES via Python expressions.
- The variable substitution mechanism of TALES ('/here/?country/thanksmessage') is used to select content based on a variable (country, domain, origin, opt-in value and so on).
- Many of the above conditional display cases actually constitute a content selection task performed using several conditional display tasks.

