The WebAbility® Network Developers - Documentation
WebAbility Site
\core\WATemplate reference

I. Structure:


- namespace:
\core\

- Direct superclass:
\core\WAClass

- Direct known subclasses:
none

II. Description:


This is the basic class to compile a template, then add elements and metaelements, and finally resolve the code of the template.

Check the Reference guide for Templates.

\core\WATemplate is serializable.


III. Reference:


3.1. Contructor:


\core\WATemplate($data)
Creates the instance.
If $data is a string, the objec will automatically compile the $data template in memory.
If $data is an array, it will copy the 3 parts of the template attributes.
  • $data: mixed: if string, the raw template. If array, a template object to copy.


3.2. Constants:

There is no constant into this class.


3.3. Attributes:


protected string $template
Is used to store the basic compiled template string.

protected array $metaelements
Is used to store the separated compiled metaelements of the basic template.

protected array $subtemplates
Is used to store the compiled sub templates.


3.4. Methods:


public WATemplate getTemplate($id)
This method is used to get the subtemplate named $id of our template object.
Will return NULL if there is no subtemplate named $id in our object.
  • $id: string, the unique ID of the sub template.


public WATemplate getClone()
This method is used to get a perfect copy of our template object.

public void metaElements($elements, $reverse)
This method is used to add the metaelements array to the template.
If the reverse flag is set, the values will be added at the beginning of the data queue.
  • $elements: array, the meta elements { variable => value }.
  • $reverse: boolean, true to insert the elements in reverse mode. Optional, False by default.

public void addElements($elements, $reverse)
This is a synonym method of metaElements method.
  • $elements: array, the meta elements { variable => value }.
  • $reverse: boolean, true to insert the elements in reverse mode. Optional, False by default.

public void addElement($variable, $value, $reverse)
This method is used to add the elements array to the template. It can inject only simple elements.
MetaElements are NOT injected by this method. Use metaElements instead.
If the reverse flag is set, the values will be added at the beginning of the data queue.
If you pass variables and values as array, the arrays MUST have the same numbers of elements and the same keys.
  • $variable: string or array, the name of each variable, 'variable' or [ 'variable', 'variable', ... ].
  • $value: string or array, the value of each variable, 'value' or [ 'value', 'value', ... ].
  • $reverse: boolean, true to insert the elements in reverse mode. Optional, False by default.

public string resolve()
This method is used to get the built final string from the template, with all the elements injected.