thezenmonkey / silverstripe-svgspritefield
模块为 Silverstripe 添加 SVGSprites
dev-master
2018-09-07 13:40 UTC
Requires
This package is auto-updated.
Last update: 2024-08-26 10:09:07 UTC
README
此模块允许您使用 SVG Sprites 为 DataObject 分配图标。它可以配置为使用默认的 sprite 文件,或者可以根据字段单独使用自定义的 sprite 文件。此模块基于 jaedb/IconField 开发,如果您需要使用多个图像文件作为图标的解决方案,则应使用后者。
要求
SilverStripe CMS ^4.2 Silverstripe SVG ^2(用于内联 Sprites)
安装
composer require thezenmonkey/silverstripe-svgspritefield
配置
Sprite 字段是 OptionSetField 的子类,使用 SVG Sprite 文件作为源数组。
使用
- 将您的 $db 字段设置为类型 Icon(例如 'Icon' => Sprite::class)
SpriteField::create($name, $title, $iconFolder)- $name 是在您的类中定义的数据库字段
- $title 是此字段的标签
- $sourceFile(可选)定义包含图标的 SVG Sprite 文件。
设置 Sprites
模块将使用数据库中存储的 symbol 作为值。 <title> 提供图标的名称。
模板
在主题中使用时,请使用标准的 SVG 使用标记,将 $Value 作为您的数据库字段名称
<svg viewBox="0 0 100 100" class="icon"> <use xlink:href="#{$Value}" /> </svg>
确保在页面上包含 SVG 源文件(设置为显示为 none)
{$SVG('mysource.svg').customBasePath('my/base/path').extraClass('myhiddenclass')}
有关正确实现,请参阅 SilverStripe SVG
致谢
待办事项
- 更多配置选项
- 内置模板
- 页面中内置 SpriteFile 包含