Template Logic
The core feature of any HTML template is its logic - Flow- and the process of executing it. The Flow defines everything that should be happening when the template is run, including various ways the template can behave in different conditions.
The process of executing the Flow, the evaluation process, is what starts up when the template is run and the server starts reading through the Flow, proceeding through one of its possible paths and executing the commands within. Designing Flow is therefore a task of defining a set of operations and directions that make the Flow-reading system operate the desired way. Many concepts and rules of the logic - such as variables, loops and conditional statements - should be familiar if one knows programming.
The operations of the evaluation process will execut are called logic commands, or just commands. There is a large set of commands available with each of them having its unique effect, such as retrieving data from Salesforce, producing a PDF file or affecting the direction of the evaluation process. Commands' operation during the evaluation process is heavily tied with variables, which are units of data that commands create and read, and which persist throughout the process. More about this in Variables and Attributes.
Besides placing in the correct commands, the Flow has to be designed so that the commands occur in the correct order. Commands cannot know what the commands after them are doing, while those evaluated later can - and often very much do - rely on the work of their predecessors. It is therefore critical to be aware of the order in which the Flow's parts are going to be evaluated in. The directions that the evaluation process can take through the Flow is dependent both on the structure of the Flow itself as well as the commands within; see Flow for how the logic's progress overall works, and Command sequence for details of how the lowest level of the evaluation process can behave.