Skip to content

Commit

Permalink
minor #3969 [html-extra] filter classes (kbond)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.x branch.

Discussion
----------

[html-extra] filter classes

A small formatting change to avoid double spaces:

```twig
class="{{ html_classes('a', false ? 'b', true ? 'c') }}"

{# before #}
class="a  c"

{# after #}
class="a c"
```

Commits
-------

a517c14f [html-extra] filter classes
  • Loading branch information
fabpot committed Apr 29, 2024
2 parents 0be2e32 + fe9ed6f commit 674c6dc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion HtmlExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ public static function htmlClasses(...$args): string
}
}

return implode(' ', array_unique($classes));
return implode(' ', array_unique(array_filter($classes, static function($v) { return '' !== $v; })));
}
}
4 changes: 2 additions & 2 deletions Tests/Fixtures/html_classes.test
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
--TEST--
"html_classes" function
--TEMPLATE--
{{ html_classes('a', {'b': true, 'c': false}, 'd') }}
{{ html_classes('a', {'b': true, 'c': false}, 'd', false ? 'e', true ? 'f', '0') }}
{% set class_a = 'a' %}
{% set class_b = 'b' %}
{{ html_classes(class_a, {(class_b): true})}}
--DATA--
return []
--EXPECT--
a b d
a b d f 0
a b

0 comments on commit 674c6dc

Please sign in to comment.