Skip to content

Commit

Permalink
Merge pull request #4237 from timkelty/html-tag-attributes-twig-filter
Browse files Browse the repository at this point in the history
Add htmlTagAttributes filter to Twig
  • Loading branch information
brandonkelly authored May 10, 2019
2 parents abe1c3c + 9bf5982 commit 8f69e68
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/web/twig/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use craft\helpers\DateTimeHelper;
use craft\helpers\Db;
use craft\helpers\FileHelper;
use craft\helpers\Html;
use craft\helpers\Json;
use craft\helpers\Sequence;
use craft\helpers\StringHelper;
Expand Down Expand Up @@ -716,6 +717,7 @@ public function getFunctions(): array
new TwigFunction('alias', [Craft::class, 'getAlias']),
new TwigFunction('actionInput', [$this, 'actionInputFunction']),
new TwigFunction('actionUrl', [UrlHelper::class, 'actionUrl']),
new TwigFunction('attr', [$this, 'attrFunction']),
new TwigFunction('cpUrl', [UrlHelper::class, 'cpUrl']),
new TwigFunction('ceil', 'ceil'),
new TwigFunction('className', 'get_class'),
Expand Down Expand Up @@ -746,6 +748,17 @@ public function getFunctions(): array
];
}

/**
* Renders HTML tag attributes with [[\craft\helpers\Html::renderTagAttributes()]]
*
* @param array $attributes
* @return Markup
*/
public function attrFunction(array $config): Markup
{
return TemplateHelper::raw(Html::renderTagAttributes($config));
}

/**
* Returns a CSRF input wrapped in a \Twig\Markup object.
*
Expand Down

0 comments on commit 8f69e68

Please sign in to comment.