Snippets

Sean Smith SVG Sprite Macro (Craft CMS)

Created by Caffeine Creations 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)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.