Homespacer>spacerMergemill Tags Guidespacer>spacerBranching Tags

spacer

Content Field

Expression

Looping

Branching

System Values

Statistics

Sections

Example

spacer

IF Structure

<?If(Expression ComparisonOperator CheckValue)?>
<?If(
Expression = CheckValue1; CheckValue2; ...)?>
<?If(
Expression = FromValue .. ToValue)?>
<?Else?>
<?EndIf?>

Here is an example to implement a logical AND with two conditions, by nesting IF structures:

<?If(...)?><?If(...)?> both conditions true, do something <?EndIf?><?EndIf?>

This implements a logical OR:

<?If(...)?> true, do something <?Else?><?If(...)?> true, do same thing <?EndIf?><?EndIf?>

An application of the IF tag in loops is where you have a list of items presented in a multicolumn table on a web page. If the table cells have a border, empty cells will look broken. To avoid this, you may use an IF structure in a cell to insert a non-breaking space (&nbsp;) when the value is empty. Here is an example:

<table width="676" border="0" cellspacing="0" cellpadding="3">
<?LOOP?><tr align="left" valign="top">
<td width="338"><p><a href="<?[CatID]{1}?>.htm"><?[CatName]{1}?></a></p></td>
<td width="338"><p><?IF([CatID]{2}=)?>&nbsp;<?ELSE?>
<a href="<?[CatID]{2}?>.htm"><?[CatName]{2}?></a><?ENDIF?></p></td>
</tr>
<?ENDLOOP?>
</table>

You don't need to do anything in the first column in this case because it is never empty if the loop is still running. All other columns need the IF structure.


Comparing Consecutive Data Values

<?If(Same[Field])?>
<?If(Same[
Field]{Column})?>

This is not a form of the <?If(expression...)?> tag. There are no comparison operator and checkvalues in the syntax, and SAME[...] is NOT an expression operand. You may include a column number and field attributes in this tag, but not a lookup extension. For this tag to be recognized, each stretch of symbols and keywords must not be broken by whitespaces.

This branching tag is only for feed-insertion fields. It compares the field's current data value for the specified column with the preceding value, and returns true if they match. So <?IF(SAME[Field])?> compares the current data value for an in-loop Field with the last value used in the previous run of the loop or, in the case of an out-loop Field, in the previous run of the template. If you include field attributes in this tag, they are applied to both the current and the preceding data values before comparison.

This tag always returns false for dynamically generated field values. If you want to compare such values, assign them to variables first and test using an <?If(expression...)?>. The tag also returns false when comparing across a field's data stream boundaries, i.e. looking behind at the beginning of a stream, or ahead at the end.

It is important to remember that the data value for the first-column field is always considered used for the current run of the template or loop. However, for field tags with a data value position offset (i.e. a column number greater than 1), a data value is considered used only when Mergemill acts on the request of such a field tag (or a field operand in an expression tag) to fetch the value. No such action is taken when the field tag appears within a hide section, or is skipped in a branching structure, such as <?If(...)?>...<?Else?><?[Field]{2}?><?EndIf?> where the IF condition returns true. A value is also not considered used if the actions to fetch values are only for carrying out comparisons in the branching tags <?IF(expression...)?>, <?IF(SAME[...)?>, and <?CASE(expression...)?>.

In the simple case where all other occurrences of Field tags do not specify a column number, <?IF(SAME[Field]{2})?> looks ahead to compare the data value to be used in the next run of the loop or template with the current value of Field.

Another example: If the maximum column number is in <?[Field]{4}?>, which inserts a value into the output, or a variable assignment block, or a section other than hide, then you may use <?IF(SAME[Field]{5})?> to do a look-ahead comparison and check if the first data value for Field in the next run of the loop body is the same as its last data value (for [Field]{4}) in the current run. This also applies to other branching tags, like <?If([Field]{5}<0)?>.

space
CASE Structure

<?StartCase?>
<?Case(
Expression ComparisonOperator CheckValue)?>
<?Case(
Expression = CheckValue1; CheckValue2; ...)?>
<?Case(
Expression = FromValue .. ToValue)?>
<?Case()?>
<?EndCase?>

When Mergemill enters a CASE structure, it runs the first CASE that is true, then skips the rest. The else case CASE() is always true, and so is run when none of the preceding CASEs within the same structure is true.

One useful application of the CASE structure is to implement "multiple" templates in one mega-template file. Each template body includes the same field tags to use the same feeds. Here is one possible structure:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><?[PageTitle]?></title>
</head>
<body>
<?STARTCASE?>
<?CASE([TemplateID]=1)?>
... template 1 body contents ...
<?CASE([TemplateID]=2)?>
... template 2 body contents ...
<?CASE([TemplateID]=...
...
<?CASE()?>
... default template body contents ...
<?ENDCASE?>
</body>
</html>

spacer

Content Field

Expression

Looping

Branching

System Values

Statistics

Sections

Example

spacer

Top of Page

Featuresspacer::spacerDownloadsspacer::spacerBuy Nowspacer::spacerSupportspacer::spacerTutorialsspacer::spacerTags Guidespacer::spacerSite Map


Copyright © 2001-2017 Cross Culture Ltd. All Rights Reserved.