PHP code example of ocubom / twig-html-extension
1. Go to this page and download the library: Download ocubom/twig-html-extension 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/ */
ocubom / twig-html-extension example snippets
$twig = new \Twig\Environment();
$twig->addExtension(new \Ocubom\Twig\Extension\HtmlExtension());
$thig->addRuntimeLoader(use Twig\RuntimeLoader\FactoryRuntimeLoader([
\Ocubom\Twig\Extension\HtmlAttributesRuntime::class => function() {
return new \Ocubom\Twig\Extension\HtmlAttributesRuntime();
},
\Ocubom\Twig\Extension\HtmlCompressRuntime::class => function() {
return new \Ocubom\Twig\Extension\HtmlCompressRuntime();
},
]));
// You can also dynamically create a RuntimeLoader
$twig->addRuntimeLoader(new class() implements RuntimeLoaderInterface {
public function load($class)
{
if (\Ocubom\Twig\Extension\HtmlAttributesRuntime::class === $class) {
return new \Ocubom\Twig\Extension\HtmlAttributesRuntime();
}
if (\Ocubom\Twig\Extension\HtmlCompressRuntime::class === $class) {
return new \Ocubom\Twig\Extension\HtmlCompressRuntime();
}
return null;
}
});