gumbraise/twig-heroicons

Heroicons 的非官方 Twig 集成

2.0.18.3 2023-11-06 21:32 UTC

This package is auto-updated.

Last update: 2024-09-06 23:06:52 UTC


README

tests

此软件包为 Twig 提供了 Heroicons 集成。

安装

使用 composer

composer require gumbraise/twig-heroicons

Symfony

您无需执行任何其他操作即可使用此扩展。

Twig

如果您直接使用 Twig,请在使用之前注册该扩展

<?php

use MarcW\Heroicons\Twig\HeroiconsExtension;
use Twig\Environment;

$twig = new Environment(/* ... */);
$twig->addExtension(new HeroiconsExtension());

用法

此扩展提供了一个 heroicon 函数,用于输出图标 SVG。

{# function signature #}
{{ heroicon(icon, style, options) }}

{# the default style is 'solid' #}
{{ heroicon('academic-cap') }}

{# use the 'outline' style #}
{{ heroicon('academic-cap', 'outline') }}

{# use the 'mini' style #}
{{ heroicon('academic-cap', 'mini') }}

{# Add a custom class to the SVG #}
{{ heroicon('academic-cap', 'outline', {
    'class': "text-green-200",
}) }}

支持选项

您可以同时添加多个选项。

  • 类名
    {{ heroicon(icon, style, {
      'class': '...'  
    }) }}
  • 笔画
    {{ heroicon(icon, style, {
      'stroke': '#......'  
    }) }}
  • 笔画宽度
    {{ heroicon(icon, style, {
      'stroke-width': '...'  
    }) }}
  • 填充
    {{ heroicon(icon, style, {
      'fill': '#......'  
    }) }}

许可证

此库采用 MIT 许可证。