Skip to content

Instantly share code, notes, and snippets.

@mcustiel
Created June 28, 2019 14:00
Show Gist options
  • Save mcustiel/0a8b6831f894a4db5f17a88526bb794c to your computer and use it in GitHub Desktop.
Save mcustiel/0a8b6831f894a4db5f17a88526bb794c to your computer and use it in GitHub Desktop.
Learning templado
<?php
require_once __DIR__ . '/../vendor/autoload.php';
//echo "PUBLIC INDEX";
//var_dump($_SERVER);
class ViewModel {
private $pageTitle = "I am the title";
public function pageTitle() {
return $this->pageTitle;
}
}
try {
$page = \Templado\Engine\Templado::loadHtmlFile(
new \Templado\Engine\FileName(__DIR__ . '/templates/index.xhtml')
);
$snippetListCollection = new \Templado\Engine\SnippetListCollection();
$sample = new \DOMDocument();
$fragment = $sample->createDocumentFragment();
$fragment->appendXML('<script type="text/javascript">console.log</script>');
$snippet = new \Templado\Engine\SimpleSnippet('bottom-scripts', $fragment);
$snippetListCollection->addSnippet($snippet);
$fragment = $sample->createDocumentFragment();
$fragment->appendXML('<style type="text/css">body{font-weight: bold;}</style>');
$snippet = new \Templado\Engine\SimpleSnippet('page-head', $fragment);
$snippetListCollection->addSnippet($snippet);
$page->applySnippets($snippetListCollection);
$page->applyViewModel(new ViewModel());
echo $page->asString() . "\n";
} catch (\Templado\Engine\TempladoException $e) {
// foreach($e->getErrorList() as $error) {
// echo (string)$error;
// }
echo (string) $e;
} catch (\Templado\Engine\ViewModelRendererException $e) {
echo (string) $e;
}
<?xml version="1.0" ?>
<!DOCTYPE HTML>
<html lang="en">
<head id="page-head">
<meta charset="utf-8"/>
<title property="pageTitle">HomePage</title>
<meta name="description" content="Templado Test" />
<meta name="author" content="Mariano Custiel" />
<link rel="stylesheet" href="css/styles.css?v=1.0"/>
</head>
<body>
<script src="js/scripts.js"></script>
<div id="bottom-scripts"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment