plasticstudio / iconfield
Icon field for Silverstripe - forked from jaedb/iconfield
Installs: 8 912
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 8
Type:silverstripe-vendormodule
Requires
- silverstripe/cms: ^4 || ^5
- silverstripe/framework: ^4 || ^5
- silverstripe/vendor-plugin: ^1 || ^2
README
composer require plasticstudio/iconfield
Description
Simplifies the use of icons in a way content authors can set icons without interfering with the asset library. Instead, the web developer provides the icon set which the end-user can use but not manipulate.
Requirements
- SilverStripe 4
Usage
- Import the required classes:
use PlasticStudio\IconField\Icon;
use PlasticStudio\IconField\IconField;
- Set your
$db
field to typeIcon
(eg'PageIcon' => Icon::class
) IconField::create($name, $title)
$name
is the database field as defined in your class$title
is the label for this field
- Add a folder containing icons to your project; icons in this folder will be used by the field as options which you can select. the default location of this folder (as defined in
_config/config.yml
) isapp/client/assets/icons/default
. If your project has apublic
directory, you'll need to make sure the path to this folder is exposed. You can override this global default in your project's own config like so:
PlasticStudio\IconField\IconField:
icons_directory: app/client/assets/different/path/to/icons
- You can also set an icon folder path on a per-field basis by using
setFolderName()
, eg:
IconField::create('SocialIcon, 'Icon')->setFolderName('app/client/assets/icons/social')
-
Use your icon in templates as you would any other property (eg
$PageIcon
). If your icon is an SVG, the SVG image data will be injected into the template. To prevent this, you can call$PageIcon.IMG
instead to enforce use of<img>
tags. -
Add a default width and height to the config.yml file to output width/height attributes on image tags
DefaultIconSize:
default_width: "120"
default_height: "120"