AppyPrinciplesGetting started
appy.pod Writing ODT templates The « else » statement

The else statement, already introduced in the general discussion about statements, deserves more attention. You have to be careful with them. POD statements are independent of each other: an if and an else statement are really 2 different statements, unlike what happens in programming languages for example. It means that POD must be able to link if and else statements, and in some cases it is not possible. The following example contains several else statements that POD could unambiguously link to their corresponding if statements.

When pod encounters an else statement, it tries to link it to the last defined if statement in the part of the POD template preceding the else statement. In this example, when encountering the else statement #4, POD links it to the if statement #3. Once the link is done, the linked if is consumed: it can't be linked to any other else statement. When POD encounters the else statement #5, it links it to the last unconsumed if statement: statement #2. In the same way, the else #6 is linked to the if #1. Here is the result.

In the example below, however, POD does not produce the desired result.

The objective was to link the else to the first if, but POD linked it to the second one instead, mistakenly rendering the last line:

With the currently presented concepts, you would be forced to replace the else by an if that duplicates and negates the condition written in the first if. This duplication could lead to maintenance problems: you could need to update the condition in the first if and forget to update its negation in the third one. So, if we want to conform to the null-IT principle and make POD a tool as invisible as possible, we need here the concept of named statement. The name must conform to the regular expression "\w+" (it can contain alphanumeric characters only + the underscore) and must be unique among the (not consumed) named statements in the POD template. The next example is the right way to produce the result we wanted to achieve in the last example: the first if is named and can thus be referred to explicitly by the else.

I let you appreciate the superb result.