API reference
This page is a compact reference for the public API of the library.
For walkthroughs and examples, use the earlier pages in the guide.
Main binding methods
DocumentBinder
bindValue(mixed $value, null|string|Element $context = null): voidbindKeyValue(string $key, mixed $value, null|string|Element $context = null): voidbindData(mixed $kvp, null|string|Element $context = null): voidbindTable(mixed $tableData, null|string|Element $context = null, ?string $bindKey = null): voidbindList(iterable $listData, null|string|Element $context = null, ?string $templateName = null): intbindListCallback(iterable $listData, callable $callback, null|string|Element $context = null, ?string $templateName = null): intcleanupDocument(): void
ComponentBinder
ComponentBinder exposes the same binding methods as DocumentBinder, but confines all binding to one expanded component element.
Context arguments
Most binding methods accept:
nullfor the whole document or whole component- an
Elementinstance - a selector
string
If the selector string does not match, DomTemplate throws ContextElementNotFoundException.
Data shapes
Values
Suitable for bindValue and bindKeyValue:
- strings
- integers
- floats
- booleans
Stringableobjects- callables returning a bindable value
Key/value data
Suitable for bindData:
- associative arrays
- objects with public properties
- objects with
#[Bind]or#[BindGetter] - objects with
asArray()
Lists
Suitable for bindList and bindListCallback:
- arrays
IteratorIteratorAggregateArrayIterator- iterable objects
Tables
Suitable for bindTable:
- row-oriented arrays with a heading row
- associative row lists
- heading => value-list maps
- double-header structures
- traversable equivalents
Composition helpers
ComponentExpander::expand(?Element $context = null): arrayPartialExpander::expand(?Element $context = null, ?DocumentBinder $binder = null): arrayPartialContent::getContent(string $name, string $extension = "html", ?string $src = null): stringPartialContent::getHTMLDocument(string $name): HTMLDocument
Key HTML attributes
data-bind:*data-listdata-templatedata-bind:listdata-bind:tabledata-table-keydata-rebinddata-elementdata-bind-debugdata-list-keep-templatedata-partial
Common exceptions
ContextElementNotFoundExceptionIncompatibleBindDataExceptionInvalidBindPropertyExceptionListElementNotFoundInContextExceptionIncorrectTableDataFormatTableElementNotFoundInContextExceptionComponentDoesNotContainContextExceptionPartialContentDirectoryNotFoundExceptionPartialContentFileNotFoundExceptionPartialInjectionPointNotFoundExceptionPartialInjectionMultiplePointExceptionCommentIniInvalidDocumentLocationExceptionCyclicRecursionException
That is the end of the main guide. If you want to jump back into the walkthrough flow, return to Home.