blob: 80bc796e1619dee9459d57c128fa245badd2f3c8 [file] [log] [blame]
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +01001``html_classes``
2================
3
4The ``html_classes`` function returns a string by conditionally joining class
5names together:
6
7.. code-block:: html+twig
8
9 <p class="{{ html_classes('a-class', 'another-class', {
10 'errored': object.errored,
11 'finished': object.finished,
12 'pending': object.pending,
13 }) }}">How are you doing?</p>
14
15.. note::
16
17 The ``html_classes`` function is part of the ``HtmlExtension`` which is not
18 installed by default. Install it first:
19
20 .. code-block:: bash
21
22 $ composer require twig/html-extra
23
24 Then, on Symfony projects, install the ``twig/extra-bundle``:
25
26 .. code-block:: bash
27
28 $ composer require twig/extra-bundle
29
30 Otherwise, add the extension explicitly on the Twig environment::
31
32 use Twig\Extra\Html\HtmlExtension;
33
34 $twig = new \Twig\Environment(...);
35 $twig->addExtension(new HtmlExtension());