if branch
With an if branch, one or more conditions are checked. Depending on which condition first returns true, that branch is displayed and the others are ignored. An if/elseif/else branch must always consist of an if branch and optionally any number of elseif branches as well as optionally a single else branch. A branch is introduced with if and closed with /if. elseif and else branches, on the other hand, are not explicitly closed. The following example shows the different forms of address when existing customers are logged in to the shop. The template has a variable $gender defined, which retrieves the corresponding gender from the customer records.switch branch
As an alternative to if branches, you can also use switch, case, and default. With switch, you introduce the branch and specify which field should be checked. After case, you write the different values without ==, and default corresponds to else.foreach loop
A foreach loop is used to repeat (iterate) code sections multiple times. The loop is introduced with foreach and closed with /foreach. The enclosed area is executed once for each element of the iterable object. With each pass, the current element of the iterable object is assigned to the so-called loop variable (in the example below $product) without var. In the following example, $productList contains a list with 3 elements. With each pass through the loop, the respective element is output with the HTML tags.The foreach loop is the only loop type in the template engine. Other loops such as for, while, or do-while do not exist.
Loop counter
The template engine does not provide an automatic counter variable inside a foreach loop. A variable such as$loop.index does not exist. If you need the position of the current element, define your own variable with var before the loop and increment it at the end of each pass.
The following example inserts a placeholder into the product list after the second product (i.e., in third position). The loop then continues normally.
0, $index == 1 corresponds to the second element.