1. Go to this page and download the library: Download phpgt/domtemplate library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phpgt / domtemplate example snippets
$html = file_get_contents("greeter.html");
$document = new \Gt\Dom\HTMLDocument($html);
if($name = $_GET["name"]) {
$binder = new \Gt\DomTemplate\DocumentBinder($document);
$binder->bindKeyValue("name-output", $name);
}
echo $document;
$html = file_get_contents("shopping-list.html");
$document = new \Gt\Dom\HTMLDocument($html);
$shoppingList = [
"Pasta",
"Rice",
"Butter",
"Eggs",
"Vegetables",
];
$binder = new \Gt\DomTemplate\DocumentBinder($document);
$binder->bindList($shoppingList);
// this removes the data-bind and data-template attributes:
$binder->cleanupDocument();
echo $document;
// The $data could be from a database, or any other source.
// For now, we're just hard-coding the data, so we can see its structure.
$data = [
[
"id" => 123,
"username" => "codyboy",
"type" => "user",
],
[
"id" => 456,
"username" => "scarlett",
"type" => "user",
],
[
"id" => 789,
"username" => "greg",
"type" => "owner",
],
];
$html = file_get_contents("user-list.html");
$document = new \Gt\Dom\HTMLDocument($html);
$binder = new \Gt\DomTemplate\DocumentBinder($document);
$binder->bindList($data);
$binder->cleanupDocument();
echo $document;
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.