TemplateTag::update - jcobban/Genealogy GitHub Wiki

$tag->update($instructions)

Up: class TemplateTag

Add an update specification to the instance of TemplateTag. This instance can be obtained by:

  • $template->getElementById($id) or more compactly $template[$id].
  • you can iterate through $tag->childNodes().
parameter description
$instructions specification of the changes to be made to the tag. The value can be null, a string, an array, or an instance of RecordSet.

Substitutions defined by calls to $tag->update are performed before substitutions requested by $template‑>set.

The parameter gives instructions as to how the tag, and its contents are to be modified as part of presenting the page to the user. In particular:

  • If the parameter is null, or an empty array, or an empty string, the tag is removed from the template.
  • If the parameter is a string the entire tag is replaced by the string value. A more intuitive equivalent of this is the JavaScript style $tag->outerHTML = $string;.
  • If the parameter is an associative array of name/value pairs, then any substitution marker that appears within the span of the tag and matches the name of an element in this array is replaced by the value. Remember that the names of insertion points are case sensitive. It is recommended that the insertion points identified by method $tag->update have identifiers with lower or mixed case, while those identified by method $template->set be all in upper case. The value assigned to a substitution name can be either a simple value, which is converted to a string to be inserted in place of the substitution marker, or it can be an array of values in which case the tag immediately containing the substitution point is replicated for each value in the array.
  • If the parameter is an array of associative arrays, or an array of instances of a class derived from class Record, or it is a RecordSet, then the tag is repeated once for each element of the outer array or row in the RecordSet, with the substitutions into each copy of the tag defined by the fields in the inner associative array or Record. This provides an easy way to generate multiple rows of a table, multiple options on a select statement, and so on. If the element in the array is a record then any of the field names, or field name synonyms, defined by the class can be used to identify substitution points. The get method used to obtain the value of a field from Record ignores the case of the field name specified in the substitution point but members of an associative array must match exactly. It is recommended to use all lower case field names for values obtained from either an associative array or an instance of Record.

Next: $tag->childNodes()