Commit 9e13c549 authored by alexpott's avatar alexpott

Issue #2447049 by Cottser, joelpittet: Add a render filter to twig

parent 3874b0c8
......@@ -110,6 +110,8 @@ public function getFilters() {
// CSS class and ID filters.
new \Twig_SimpleFilter('clean_class', '\Drupal\Component\Utility\Html::getClass'),
new \Twig_SimpleFilter('clean_id', '\Drupal\Component\Utility\Html::getId'),
// This filter will render a renderable array to use the string results.
new \Twig_SimpleFilter('render', 'twig_render_var'),
);
}
......
......@@ -115,6 +115,10 @@ public function testTwigWithoutFilter() {
'expected' => '<div id="quotes-here"><span class="gray-like-a-bunny bem__ized--top-feature" id="quotes-here">ID and class. Having the same ID twice is not valid markup but we want to make sure the filter doesn\'t use \Drupal\Component\Utility\Html::getUniqueId().</span></div>',
'message' => 'Class and ID filtered.',
),
array(
'expected' => '<div><strong>Rendered author string length:</strong> 24.</div>',
'message' => 'Render filter string\'s length.',
),
);
foreach ($elements as $element) {
......
......@@ -21,3 +21,4 @@
<div><span{{ attributes|without('id', 'class') }}>Without id and class attributes.</span></div>
<div><span{{ attributes }}>All attributes again.</span></div>
<div id="{{ 'quotes Here!'|clean_id }}"><span class="{{ 'Gray like a bunny!'|clean_class }} {{ 'BEM__ized--Top Feature'|clean_class }}" id="{{ 'quotes Here!'|clean_id }}">ID and class. Having the same ID twice is not valid markup but we want to make sure the filter doesn't use \Drupal\Component\Utility\Html::getUniqueId().</span></div>
<div><strong>Rendered author string length:</strong> {{ quote.author|render|length }}.</div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment