What problem does HTML logic solve?
In the IPS Community Suite, our templates are the 'view', i.e. how the data is rendered as HTML to the screen. However, basic HTML has no logic capabilities; what is in the HTML file is what is sent to the browser. In a complex application like ours, we need some way to make decisions about what is output.
These decisions could potentially be made in the PHP backend, but that isn't appropriate in most cases; the backend should be focused on processing the data, while the view (our templates) control how the data is displayed.
HTML logic allows us to make these decisions inside our templates. It mixes standard HTML with some special tags and flow-control statements, most of which are very similar to PHP.
What other features do templates have?
The result is that in one template, we can have logic that says output some HTML if a certain condition is met, or different HTML otherwise. We can also do loops on data, reducing repetition. We also have some special tags that call output plugins to transform values in some way (for example, to render dates from a timestamp).
Basic syntax
There's three basic types of syntax you'll see. We will explore these in more detail in later steps.
Logic tags
Double-curly parenthesis. Controls flow in a template. In these tags, the expressions can be any valid PHP expression. Some examples:
/* Basic structure */ {{if $condition}} ... {{else}} ... {{endif}} /* Examples of other expressions */ {{if !$condition}} {{if ( $color == 'green' && $size == 'big' ) || $condition}} {{if count( $value ) > 2}}
Variables
Single-curly parenthesis. Outputs values passed into the template (or values from elsewhere, e.g. a loop).
{$value}
Output plugins
Pass the provided value through the specified output plugin.
{pluginName="value"}
Report Guide