-
-
Notifications
You must be signed in to change notification settings - Fork 4
Home
Built on top of PHP.Gt/Dom, PHP.Gt/DomTemplate provides dynamic data binding to DOM Documents, document templating and reusable HTML components.
Directly manipulating the DOM in your code can lead to tightly coupling the logic and view. Binding data using custom elements and data attributes leads to highly readable, maintainable view files that are loosely coupled to the application logic.
An example of what this looks like in your HTML views:
<h1>Your order</h1>
<p>The order total is <span data-bind:text="priceFormatted">£0.00</span></p>
<p>Items in your order:</p>
<ul>
<li data-template>
<span data-bind:text="name">Item Name</span>
<span data-bind:text="priceFormatted">£0.00</span>
</li>
</ul>
In the above example, the HTML can be maintained separately. The entire structure can change, without having to communicate this to PHP, as long as the data-bind:*
and data-template
attributes are applied to the appropriate elements. This is what's referred to as loosely coupled - the page logic is loosely coupled to the page view, leading to highly maintainable systems.
PHP.Gt/DomTemplate is a separately maintained component of PHP.Gt/WebEngine.
- Bind data to HTML elements with
data-bind
attributes - Bind key modifiers
- Inject data into HTML with
{{curly braces}}
- Bind lists of data with
data-list
attributes - Bind nested lists with
data-bind:list
- Automatically remove unbound elements
- Bind tabular data into HTML tables
- Using objects to represent bindable data