This documentation describes unreleased changes on the main branch.

asset_svg()

Twig function of the framework; its result is HTML and is printed without escaping.

{{ asset_svg(name, attributes = {}) }}

The markup of an SVG asset, to place it inline, e.g. an icon styled with CSS. The XML declaration and doctype are removed and the given attributes are set on the root svg element. The output is HTML and is printed unescaped. An unknown or invalid name, a file that is no .svg or has no root element svg are errors.

{{ asset_svg('icons/menu.svg', { class: 'size-6 fill-current', 'aria-hidden': 'true' }) }}
ParameterTypeDefaultDescription
namestringrequiredPath of the SVG asset below assets/, e.g. icons/menu.svg; it may start with @child/ or with the instance's own prefix (@theme/ or @plugin/).
attributesarray<string, string|int|bool>[]Attributes for the root element; classes are added to those of the file, true sets an attribute without value, false removes it.

Returns string