Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Jun 17, 2019
1 parent 2c1b60b commit 1734c1b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Directly manipulating the DOM in your code can lead to tightly coupling the logi

Consider a page with an unordered list (`<ul>`). Within the list there should be a list item (`<li>`) for every element of an array of data.

In this example, we will simply use an array to contain the data, but the data can come from a data source such as a database.
In this example, we will simply use an array to contain the data, but the data can come from a data source such as a database, as long as it is `iterable`.

### Source HTML (`example.html`)

Expand All @@ -53,9 +53,11 @@ In this example, we will simply use an array to contain the data, but the data c
<?php
require "vendor/autoload.php";

use Gt\DomTemplate\HTMLDocument;

$html = file_get_contents("example.html");
$document = new \Gt\DomTemplate\HTMLDocument($html, "./_component");
$document->prepareTemplates();
$document = new HTMLDocument($html, "./_component");
$document->extractTemplates();

$data = [
["id" => 1, "title" => "Tomatoes"],
Expand All @@ -65,7 +67,7 @@ $data = [
];

$outputTo = $document->getElementById("groceries");
$outputTo->bind($data);
$outputTo->bindList($data);
```

### Output:
Expand All @@ -84,4 +86,11 @@ $outputTo->bind($data);
<p>The use of a custom element is more useful on more complex pages, but is shown above as an example.</p>
```

Features at a glance
--------------------

+ HTML components - organise and reuse DOM trees by storing separate components in their own HTML files, and including them using custom HTML tags.
+ Binding of dynamic data - bind key value pairs, associative arrays, lists of associative arrays and even nested lists.
+ Use standards compliant techniques for templates and components.

[dom]: https://www.php.gt/dom

0 comments on commit 1734c1b

Please sign in to comment.