class TemplateTag - jcobban/Genealogy GitHub Wiki
The class TemplateTag represents a single HTML or XML tag in a template. Note that $template‑>getDocument()
returns an instance of TemplateTag which contains the entire Document Object Model of the template. That is it is equivalent to the JavaScript document
variable.
This class provides access to the following attributes of the tag:
attribute | description |
---|---|
tagName | the tag name |
id | id attribute value. This attribute is always defined but is an empty string if the id attribute is not specified on the tag. |
template | the containing instance of class Template |
attributes | associative array of attributes on the tag. Loop through them using foreach($tag‑>attributes as $name => $value) , check for existence by either isset($tag‑>attributes[$name]) or array_key_exists($name, $tag‑>attributes) and access value by $tag‑>attributes[$name] . |
outerHTML | If used in an expression this is the entire text of the tag. If used on the left-hand side of an assignment it replaces the tag in the expansion of the template. See $tag->outerHTML() for details. |
innerHTML | If used in an expression this is the contents of the tag between the opening and closing tags. If used on the left-hand side of an assignment it replaces the contents between the opening and closing tags. See $tag->innerHTML() for details. |
childNodes | this is a collection of instances of TemplateTag representing the tags which are immediately under the tag which can be iterated through. It invokes the function $tag->childNodes() to provide a JavaScript like user interface. It is read-only. |
These are all public because they are accessed by the class Template.
For example if a portion of the template is:
<div id="tagid" parm="something">
<span>contents</span>
</div>
$tag = $template['tagid'];
print $tag.id; // displays 'tagid'
foreach($tag‑>attributes as $name => $value)
{
print "$name=$value,";
}
$t = $tag->template; // returns $template
$html = $tag->outerHTML; // from the opening <div to the closing </div>
$inner = $tag->innerHTML; // the <span> tag
$tag->innerHTML = "<b>something else</b>"; // replaces the <span> tag and its contents
$tag->outerHTML = $string; // replaces the entire <div>
- new TemplateTag($template, $start, $inTemplate)
- $tag->printTag()
- $tag->outerHTML()
- $tag->innerHTML()
- $tag‑>replace($match, $replace)
- $tag->addChild($atag)
- $tag->replChild($oldtag, $newtag)
- $tag->update($instructions)
- $tag->childNodes()
- $tag->parentNode()
- $tag->getElementsByTagName($tagname)
- $tag[$key]