tvaliasek/iconmacros

此包已被弃用且不再维护。未建议替代包。

将 svg 图标嵌入 latte 模板的 icon latte 宏

1.0.6 2016-10-06 20:40 UTC

This package is auto-updated.

Last update: 2019-02-20 19:49:04 UTC


README

实验性自定义 latte 宏用于嵌入 svg 图标,svg 文件将自动清理。

安装

$ composer require tvaliasek/iconmacros

配置

目前,配置是通过在 IconMacro.php 文件中覆盖常量来实现的

class IconMacro extends Macroset {

    /*@var string - relative path to folder with icon files */
    const ICONS_PATH = '/../../../../www/img/icons';
    /*@var string - css class name prefix*/
    const ICON_CSS_CLASSNAME_PREFIX = 'icon';
    /*@var string - mime type identifier for SVG images*/
    const SVG_MIME_TYPE = 'image/svg+xml';
    /*@var boolean - filter out non-minified files in icons folder (without .min.svg extension)*/
    const ONLY_MINIFIED = false;
    ...

注册

latte:
	macros:
		- \Tvaliasek\IconMacros\IconMacro

使用

{* macro icon will embed file named envelope.svg and fill attributes will be preserved *}
<span> {icon envelope cyan in-text} </span>

{* macro clearIcon will embed file named envelope.svg and fill attributes will be stripped *}
<span> {clearIcon envelope cyan in-text} </span>

结果

<!-- icon -->
<span>
<svg class="icon icon-envelope icon-cyan icon-in-text" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24" height="24" viewBox="0 0 24 24">
  <path fill="#000000" d="M20,8L12,13L4,8V6L12,11L20,6M20,4H4C2.89,4 2,4.89 2,6V18A2,2 0 0,0 4,20H20A2,2 0 0,0 22,18V6C22,4.89 21.1,4 20,4Z"></path>
</svg>
</span>

<!-- clearIcon -->
<span>
<svg class="icon icon-envelope icon-cyan icon-in-text" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24" height="24" viewBox="0 0 24 24">
  <path d="M20,8L12,13L4,8V6L12,11L20,6M20,4H4C2.89,4 2,4.89 2,6V18A2,2 0 0,0 4,20H20A2,2 0 0,0 22,18V6C22,4.89 21.1,4 20,4Z"></path>
</svg>
</span>