Logic and Loops
Logic is used to show content based on a test. Repeaters are used to list elements like Products, Pages, or Contacts.
Logic IF
The <logic:if> control performs a test, and renders everything inside the tag if the test is true. The test is defined within the test="true" attribute, and is often an API call.
The following examples are usually defined in the website design to show content dynamically:
IF the current visitor is logged in, show "you are logged in".
IF the current page is the "About Us" page, show a heading.
Logic ELSE
The <logic:else> control defines an alternate region to show in the case that an IF test fails. Extending the above examples:
IF the current visitor is logged in, show "you are logged in".
ELSE show "You are not logged in":
IF the current page is the "About Us" page, show a heading.
ELSE show a message "Another Page".
The ELSE tag must be defined after an IF tag.
You can add additional Else tags with test conditions to be checked if the previous test fails:
Loops: The Data Repeater Control
<data:repeater> is commonly used to list elements like Products, Pages, or Contacts.
The Data Repeater repeats everything inside the tag, for each item in a given data source.
The "as" attribute defines the name of the variable, and the "datasource" attribute usually defines an API call to retrieve a Page, Product or Contact.
The following example will list all Posts:
Or, to show all contacts in a specific Group:
DataLimit and DataStart Attributes
The DataLimit attribute can be used to limit the number of records displayed. For example, you may wish to only show three Posts:
The DataStart attributes may be used in addition to the DataLimit attribute to show from a record, to a record. As an example, the
following code will only show all Posts, starting at the Third Post:
Note: DataLimit is an array index, so the first record is at index 0:
[0 => "First Post"]
[1 => "Second Post"]
[2 => "Third Post"]
Advanced: Ordering & Filtering
Click here to read more about how to use the DataFilter attribute to filter records (eg. show all products, greater than $100 in value).
Click here to see an example illustrating how to order
records (eg. by value or alphabetically).