This extension extends the twig/html-extra with additional HTML related Twig functions:
html_id('my-prefix'): Returns a random, but for this request unique prefixed IDhtml_attribute('id', 'html-id'): Renders a HTML attribute, e.g.id="html-id"html_attributes({ id: 'html-id', class: {first: true, second: false}, data: {test: '1'} }): Renders a map of HTML attributes, result:id="html-id" class="first" data-test="1"html_styles({ 'font-size': '12px', 'font-weight': bold }): Renders CSS properties and values, result:font-size: 12px, font-weight: bold
- Twig >=3.20
- PHP >=8.1
The recommended way to install this extension is via Composer:
composer require gglnx/twig-html-extended-extraAfterwards you can add this extension to Twig:
require_once '/path/to/vendor/autoload.php';
$twig = new \Twig\Environment($loader);
$twig->addExtension(new \Gglnx\TwigHtmlExtendedExtra\Extension\HtmlExtendedExtension());