Jump to content

Template syntax

  1. Introduction to template syntax

    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 ca
  2. Using expressions in logic

    As mentioned in the first step, any valid PHP expression can be used in HTML logic tags. You'll often just be checking if an expression is true or false: {{if $value}} ... {{endif}} ...but there are many other possibilities. You can also use normal PHP functions in your expressions. For example, you may need to determine if an array has any items, so PHP's count function is appropriate: {{if count(
  3. if/elseif/else logic

    The most basic logic check is a simple if/else. This allows you to put HTML if a condition matches, or something else if it doesn't. The syntax is simply: {{if [expression]}} HTML to output if expression is true {{else}} HTML to output if expression was not true {{endif}}   There's also an elseif tag which allows you to specify other conditions to check if earlier conditions d
  4. Loops

    Standard PHP loop types are supported as HTML logic tags.   Foreach {{foreach [expression]}} ... {{endforeach}} Expression is anything PHP would support in a loop. The variables the loop defines are available within the body of the loop: <ul> {{foreach $arrayOfItems as $id => $item}} <li>{$id}: {$item}</li> {{endforeac
  5. Variables

    Each template bit can have variables passed into it by the backed PHP code, and these variables can be used by the template bit to control the display. Consult either the template editor or designer's mode guides (depending on your preference) to find out how to determine which variables are available to a template. As well as these local variables, you can access the various objects created by the IPS4 PHP framework.   &
  6. Template plugins

    It's often useful to transform raw values in some way, and this is achieved in IPS4 with template plugins. Template plugins take a value, and optionally some arguments, and output some transformed value. The syntax for template tags is: {pluginkey="<value>" argument="..."} The value can be a normal string, or it could be a variable coming from elsewhere. Template plugins can always be used in templates, but some can also be used in CSS files. Those that can are identified
  7. Using arbitrary PHP in templates

    It is possible to use arbitrary PHP in your templates. Generally this is discouraged, but in some situations a simple statement can be of benefit to initialize a variable or aid debugging (for example). Note: templates also support a special expression template tag; consider using this tag in favor of arbitrary PHP. We cover the tag in a later step of this guide. To use PHP, you can enclose your statement in double-curly parenthesis, like
×
×
  • Create New...