Snippets

Sean Smith SVG Sprite Macro (Craft CMS)

Created by Sean Smith last modified

This macro will work with SVG sprites to output the desired icon with settings for

  • iconId (this is the symbol id in your sprite)
  • className
  • width
  • height
{% macro icon(iconId, className, width, height) %}
    <svg class="icon {{ className }}" role="img" title="{{ iconId }}" width="{{ width|default('24') }}"  height="{{ height|default('24') }}">
        <use xlink:href="{{ url('/assets/images/icons.svg#' ~ iconId) }}"></use>
    </svg>
{% endmacro %}

Then in your Template use the macro like this

{{ macros.icon("symbol-name", "css-class-name", "40", "40") }}

Comments (0)