PHP code example of dahas / easy-template
1. Go to this page and download the library: Download dahas/easy-template 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/ */
dahas / easy-template example snippets
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>[[TITLE]]</title>
</head>
<body>
<h1>[[HEADER]]</h1>
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">NAME</th>
<th scope="col">AGE</th>
<th scope="col">CITY</th>
</tr>
</thead>
<tbody>
<!-- {{ROWS}} begin -->
<tr>
<th scope="row">[[UID]]</th>
<td>[[NAME]]</td>
<td>[[AGE]]</td>
<td>[[CITY]]</td>
</tr>
<!-- {{ROWS}} end -->
</tbody>
</table>
</body>
</html>
$template = new EasyTemplate("path/to/template.html");
<!-- {{ROWS}} begin -->
<tr>
<th scope="row">[[UID]]</th>
<td>[[NAME]]</td>
<td>[[AGE]]</td>
<td>[[CITY]]</td>
<td>[[COUNTRY]]</td>
</tr>
<!-- {{ROWS}} end -->
$slice = $this->template->getSlice("ROWS");
$slice = new EasyTemplate("path/to/slice.html");
$template = new EasyTemplate("path/to/template.html");
$markers = [
"TITLE" => "The title",
"HEADER" => "Easy Template is cool!"
];
$slice = $template->getSlice("ROWS");
$rows = $slice->parse([
"UID" => 1,
"NAME" => "Angus Young",
"AGE" => 66,
"CITY" => "Melbourne",
]);
$slices = [
"ROWS" => $rows
];
return $template->parse($markers, $slices);