-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle [vars] section of comment ini (#401)
* build: upgrade dom requirement and loosen version range * docs: update examples * feature: trim whitespace when there are only template children closes #363 * feature: handle vars section in partial comment ini closes #400 * tweak: nullable call * tweak: stan improvement
- Loading branch information
Showing
5 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
use Gt\Dom\HTMLDocument; | ||
use Gt\DomTemplate\DocumentBinder; | ||
use Gt\DomTemplate\PartialContent; | ||
use Gt\DomTemplate\PartialExpander; | ||
|
||
require(__DIR__ . "/../../vendor/autoload.php"); | ||
// EXAMPLE CODE: https://github.com/PhpGt/DomTemplate/wiki/Partials#pre-binding-using-template-variables | ||
|
||
$partialContent = <<<HTML | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>My website :: {{site-heading ?? Home}}</title> | ||
</head> | ||
<body> | ||
<h1 data-bind:text="site-heading">My website!</h1> | ||
<main data-partial> | ||
</main> | ||
<footer> | ||
<p>Thanks for visiting</p> | ||
</footer> | ||
</body> | ||
</html> | ||
HTML; | ||
|
||
$pageAbout = <<<HTML | ||
<!-- | ||
extends=main-template | ||
[vars] | ||
site-heading=About me | ||
--> | ||
<h2>About me</h2> | ||
<p>This is my about me page on my amazing website!</p> | ||
HTML; | ||
|
||
$baseDirectory = sys_get_temp_dir() . "/phpgt-domtemplate-example"; | ||
$partialDirectory = "$baseDirectory/_partial"; | ||
mkdir($partialDirectory, 0775, true); | ||
file_put_contents("$partialDirectory/main-template.html", $partialContent); | ||
|
||
$document = new HTMLDocument($pageAbout); | ||
$partial = new PartialContent($partialDirectory); | ||
$expander = new PartialExpander($document, $partial); | ||
$binder = new DocumentBinder($document); | ||
$binder->cleanDatasets(); | ||
$expander->expand(binder: $binder); | ||
|
||
echo $document; | ||
|
||
// Remove the temporary files: | ||
foreach(new RecursiveIteratorIterator( | ||
new RecursiveDirectoryIterator($baseDirectory, FilesystemIterator::SKIP_DOTS), | ||
RecursiveIteratorIterator::CHILD_FIRST | ||
) as $file) { | ||
if($file->isDir()) rmdir($file->getRealPath()); | ||
else unlink($file->getRealPath()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters