Attention
TYPO3 v8 has reached its end-of-life March 31st, 2020 and is not maintained by the community anymore. Looking for a stable version? Use the version switch on the top left.
There is no further ELTS support. It is recommended that you upgrade your project and use a supported version of TYPO3.
Icon API¶
Since version 7.5 TYPO3 CMS provides an Icon API for all icons in the TYPO3 backend.
Registration¶
All icons must be registered in the IconRegistry
.
To register icons for your own extension use the following
code in your ext_localconf.php
file:
$iconRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
\TYPO3\CMS\Core\Imaging\IconRegistry::class
);
$iconRegistry->registerIcon(
$identifier, // Icon-Identifier, z.B. tx-myext-action-preview
\TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider::class,
['source' => 'EXT:myext/Resources/Public/Icons/action-preview.svg']
);
IconProvider¶
The TYPO3 core ships three IconProvider which can be used:
BitmapIconProvider
– For all kind of bitmap icons (format like: gif, png, jpeg, etc)SvgIconProvider
– For all SVG iconsFontawesomeIconProvider
– For all icons which can be found in fontawesome.io
In case your need special IconProvider you can implement your own,
your class has to implement the IconProviderInterface
.
Use icons in your code¶
You can use the Icon API to receive icons with in your PHP code or directly in fluid.
The PHP way¶
Your can use the IconFactory
to request an icon:
$iconFactory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
\TYPO3\CMS\Core\Imaging\IconFactory::class
);
$icon = $iconFactory->getIcon(
'tx-myext-action-preview',
\TYPO3\CMS\Core\Imaging\Icon::SIZE_SMALL,
'overlay-identifier'
);
$this->view->assign('icon', $icon);
The Fluid ViewHelper¶
You can also simple use the Fluid ViewHelper to render an icon in your view:
{namespace core = TYPO3\CMS\Core\ViewHelpers}
<core:icon identifier="my-icon-identifier" size="small" />