From 226dc8a6def7e40c23949d07e9e44c26176c1ea0 Mon Sep 17 00:00:00 2001 From: Tom Bamford Date: Mon, 19 Mar 2018 23:00:28 +0100 Subject: [PATCH 1/2] Creates add_attribute twig function Replicates the Drupal twig function create_attribute for patternlab https://www.drupal.org/docs/8/theming/twig/functions-in-twig-templates#create_attribute --- dist/functions/create_attribute.function.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 dist/functions/create_attribute.function.php diff --git a/dist/functions/create_attribute.function.php b/dist/functions/create_attribute.function.php new file mode 100644 index 0000000..72e0874 --- /dev/null +++ b/dist/functions/create_attribute.function.php @@ -0,0 +1,12 @@ + array('html')) +); \ No newline at end of file From ff39b8fe14ce78afd08154fa2ad8dfb407b5cb42 Mon Sep 17 00:00:00 2001 From: Tom Bamford Date: Tue, 20 Mar 2018 13:07:59 +0100 Subject: [PATCH 2/2] Loops through each attribute --- dist/functions/create_attribute.function.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dist/functions/create_attribute.function.php b/dist/functions/create_attribute.function.php index 72e0874..a13b07f 100644 --- a/dist/functions/create_attribute.function.php +++ b/dist/functions/create_attribute.function.php @@ -3,9 +3,8 @@ $function = new Twig_SimpleFunction( 'create_attribute', function ($attributes = []) { - if (isset($attributes) && isset($attributes['class'])) { - $classes = join(' ', $attributes['class']); - return ' class="' . $classes .'"'; + foreach ($attributes as $key => $value) { + print ' ' . $key . '="' . join(' ', $value) . '"'; } }, array('is_safe' => array('html'))