@@ -59,29 +59,37 @@ refers to the icons located in the ``header`` directory.
59
59
Loading Icons
60
60
-------------
61
61
62
+ To include an icon in your template, two syntaxes are available.
63
+
64
+ .. tip ::
65
+
66
+ To use the HTML syntax, you need the ``symfony/ux-twig-component `` package:
67
+
68
+ .. code-block :: terminal
69
+
70
+ $ composer require symfony/ux-twig-component
71
+
72
+
62
73
.. code-block :: twig
63
74
64
- {# includes the contents of the 'assets/icons/user-profile.svg' file in the template #}
75
+ {# Includes the contents of 'assets/icons/user-profile.svg' in the template: #}
65
76
{{ ux_icon('user-profile') }}
77
+ {# Same in alternative HTML syntax: #}
78
+ <twig:ux:icon name="user-profile" />
66
79
67
- {# icons stored in subdirectories must use the 'subdirectory_name:file_name' syntax
68
- (e.g. this includes 'assets/icons/admin/user-profile.svg') #}
80
+ {# Includes 'assets/icons/admin/user-profile.svg': #}
69
81
{{ ux_icon('admin:user-profile') }}
82
+ <twig:ux:icon name="admin:user-profile" />
70
83
71
- {# this downloads the 'user-solid.svg' icon from the 'Flowbite' icon set via ux.symfony.com
72
- and embeds the downloaded SVG contents in the template #}
73
- {{ ux_icon('flowbite:user-solid') }}
74
-
75
- The ``ux_icon() `` function defines a second optional argument where you can
76
- define the HTML attributes added to the ``<svg> `` element:
77
-
78
- .. code-block :: html+twig
84
+ {# Adding a CSS class or other attribute to the `<svg>` element: #}
85
+ {{ ux_icon('user-profile', {class: 'w-4', 'aria-hidden': 'true' }) }}
86
+ <twig:ux:icon name="user-profile" class="w-4" aria-hidden="true" />
79
87
80
- {{ ux_icon('user-profile', {class: 'w-4 h-4'}) }}
81
- {# renders <svg class="w-4 h-4"> ... </svg> #}
88
+ {# Download the 'user-solid.svg' icon from the 'Flowbite' icon set via ux.symfony.com: #}
89
+ {{ ux_icon('flowbite:user-solid') }}
90
+ <twig:ux:icon name="flowbite:user-solid" />
82
91
83
- {{ ux_icon('user-profile', {height: '16px', width: '16px', 'aria-hidden': true}) }}
84
- {# renders <svg height="16" width="16" aria-hidden="true"> ... </svg> #}
92
+ You can set default attributes for all icons in your `Configuration `_.
85
93
86
94
87
95
Icon Sets
@@ -170,34 +178,6 @@ icons in the "Tabler Icons" set, use the following command:
170
178
Page 1/3. Continue? (yes/no) [yes]:
171
179
>
172
180
173
- HTML Syntax
174
- ~~~~~~~~~~~
175
-
176
- In addition to the ``ux_icon() `` function explained in the previous sections,
177
- this package also supports an alternative HTML syntax based on the ``<twig:ux:icon> ``
178
- tag:
179
-
180
- .. code-block :: html
181
-
182
- <!-- renders "user-profile.svg" -->
183
- <twig:ux:icon name =" user-profile" class =" w-4 h-4" />
184
- <!-- renders "admin/user-profile.svg" -->
185
- <twig:ux:icon name =" admin:user-profile" class =" w-4 h-4" />
186
- <!-- renders 'user-solid.svg' icon from 'Flowbite' icon set via ux.symfony.com -->
187
- <twig:ux:icon name =" flowbite:user-solid" />
188
-
189
- <!-- you can also add any HTML attributes -->
190
- <twig:ux:icon name =" user-profile" height =" 16" width =" 16" aria-hidden =" true" />
191
-
192
- .. tip ::
193
-
194
- To use the HTML syntax, the ``symfony/ux-twig-component `` package must be
195
- installed in your project:
196
-
197
- .. code-block :: terminal
198
-
199
- $ composer require symfony/ux-twig-component
200
-
201
181
Downloading Icons
202
182
-----------------
203
183
@@ -318,45 +298,6 @@ Rendering Icons
318
298
and embeds the downloaded SVG contents in the template #}
319
299
{{ ux_icon('flowbite:user-solid') }}
320
300
321
- HTML Syntax
322
- ~~~~~~~~~~~
323
-
324
- .. code-block :: html+twig
325
-
326
- <twig:ux: icon name="user-profile" />
327
-
328
- {# Renders "user-profile.svg" #}
329
- <twig:ux: icon name="user-profile" class="w-4 h-4" />
330
-
331
- {# Renders "sub-dir/user-profile.svg" (sub-directory) #}
332
- <twig:ux: icon name="sub-dir:user-profile" class="w-4 h-4" />
333
-
334
- {# Renders "flowbite:user-solid" from ux.symfony.com #}
335
- <twig:ux: icon name="flowbite:user-solid" />
336
-
337
- Default Attributes
338
- ~~~~~~~~~~~~~~~~~~
339
-
340
- You can set default attributes for all icons in your configuration. These attributes will be
341
- added to all icons unless overridden by the second argument of the ``ux_icon `` function.
342
-
343
- .. code-block :: yaml
344
-
345
- # config/packages/ux_icons.yaml
346
- ux_icons :
347
- default_icon_attributes :
348
- fill : currentColor
349
-
350
- Now, all icons will have the ``fill `` attribute set to ``currentColor `` by default.
351
-
352
- .. code-block :: twig
353
-
354
- # renders "user-profile.svg" with fill="currentColor"
355
- {{ ux_icon('user-profile') }}
356
-
357
- # renders "user-profile.svg" with fill="red"
358
- {{ ux_icon('user-profile', {fill: 'red'}) }}
359
-
360
301
Icon Aliases
361
302
~~~~~~~~~~~~
362
303
0 commit comments