-
-
Notifications
You must be signed in to change notification settings - Fork 3
Debugging
DomTemplate is small, but when a larger page has many binds it is still helpful to know where a given value came from.
That is where data-bind-debug comes in.
Add data-bind-debug to a scope element:
<section data-bind-debug>
<h1 data-bind:text="name">Guest</h1>
<p><a data-bind:href="emailLink" data-bind:text="email">guest@example.com</a></p>
</section>Now when a bind happens within that scope, DomTemplate records the source file and line number on the affected elements.
After binding, an element might end up with:
<h1 data-bind-debug="text=app/Controller.php:10">Cody</h1>Or for multiple properties:
<a data-bind-debug="text=app/Controller.php:10,href=app/Controller.php:10" href="mailto:cody@example.com">cody@example.com</a>This makes it much easier to answer the question, "which bind call wrote this?"
Only elements inside a data-bind-debug scope collect debug entries.
That means we can add it to a single section of the page while leaving the rest untouched, or even just add the debug attribute to the single element we want to inspect.
cleanupDocument() removes an empty data-bind-debug marker from scope elements, but it keeps populated debug attributes on elements that actually recorded bind information, so we get useful debug output without leaking empty marker attributes.
Debug information also works with generated content such as:
- list items produced by
bindList - table cells produced by
bindTable
That is particularly handy when the final nodes did not even exist in the original HTML.
Another useful debugging improvement is selector-based bind contexts.
If we write:
$binder->bindKeyValue("name", "Cody", "#missing");and the selector does not match, DomTemplate throws ContextElementNotFoundException instead of a low-level type error.
That usually gives us a much faster route to the actual mistake in the template or controller code.
This is the end of the guide. Read the API reference for the method and exception cheat sheet.
PHP.GT/DomTemplate is a separately maintained component of PHP.GT/WebEngine.