The View uses templates to specify the visible elements. The View accepts Template objects, strings, numbers, or arrays of these.
Template objects capture an XML-like tree of elements. Each Template object has a tag that can be a standard HTML tag string, a published Component string, or a Component class. It also contains any attributes and children associated with each element. Unlike XML, children can be any JavaScipt type.
Template trees are normally built using Template Markup Language (TML).
new Template(tag, props, children)
tag (required)props (optional, default: {}).children (optional, default: [])checkChildTags(tagsAllowed, msg)
Check that the Template object's children array has valid children. Only Template children are examined; strings and numbers are ignored. The check is made with assert(), so a failure throws rather than returning.
tagsAllowed
An array of allowed tags. Each tag string may have one of the following characters appended:
+*? A child tag is accepted if it prefix-matches any entry in tagsAllowed (the test is s.match('^'+tag)), so an allowed tag that begins with a child's tag also admits that child.
msg
A message used as the prefix of the assertion failure message.
Nothing. The method only asserts; it fails an assertion if the children are not valid.
clone()
Returns a new Template object identical to this one. Only the direct children of the template are copied.
A Template object.
findChildrenByClassName(className, …)
Searches the template tree from this Template object down, for children that have any of the classNames. Returns an array of children that have any of the specified classes.
className (all arguments)An array of Template objects representing any descendant of this Template object having any of the specified CSS classNames.
getChildByTag(tag)
Return the first child that has the specified tag. Only the direct children of the Template object are searched.
tagReturn value A child Template that has a matching tag, or undefined if not found (the result of Array.find).
getChildrenByTag(tag)
Return an array of children that have the specified tag. Only the direct children of this Template object are searched.
An array of children that have the specified tag.
splitChildrenByTag(tag, ...)
Segregate child templates by tag. The arguments are a set of tags. It returns an array containing arrays. The outer array has an array element for each tag argument, plus one more for children not matching any tag argument. Children with matching tags are placed in the results array element corresponding to the tag position in the arguments. Strings, Numbers, and children that don't correspond to any category are placed in the last result array.
An array of arrays.
toString()
Convert this Template and its children into an XML string.
Note: this method is for Template objects only. To convert any TML result (Template objects, strings, or Numbers) to a string, use tml.toString(value); see tml.md.
An XML string.
toText()
Convert this Template's children into a string containing only the text content.
A string.
childrenThe children array that was passed to the constructor, then flattened with blank strings filtered out. If no children were passed, then this is an empty array.
An array containing Template objects and/or any JavaScipt type.
propsThe props object that was passed to the constructor. If no props object was passed, then this is an empty object.
An object.
tagThe tag string or Component class that was passed to the constructor.
A String or Component class.