1. Go to this page and download the library: Download ocubom/twig-svg-extension library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ocubom / twig-svg-extension example snippets
$twig = new \Twig\Environment();
$twig->addExtension(new \Ocubom\Twig\Extension\SvgExtension());
$twig->addRuntimeLoader([
\Ocubom\Twig\Extension\SvgRuntime::class => function () use ($paths) {
return new \Ocubom\Twig\Extension\SvgRuntime(
new \Ocubom\Twig\Extension\Svg\Provider\FileSystem\FileSystemLoader($paths)
);
},
\Ocubom\Twig\Extension\Svg\Provider\FontAwesome\FontAwesomeRuntime::class => function () use ($paths) {
return new \Ocubom\Twig\Extension\Svg\Provider\FontAwesome\FontAwesomeRuntime(
new \Ocubom\Twig\Extension\Svg\Provider\FontAwesome\FontAwesomeLoader($paths)
);
},
\Ocubom\Twig\Extension\Svg\Provider\Iconify\IconifyRuntime::class => function () use ($paths) {
return new \Ocubom\Twig\Extension\Svg\Provider\Iconify\IconifyRuntime(
new \Ocubom\Twig\Extension\Svg\Provider\Iconify\IconifyLoader($paths)
);
},
]);
// You can also dynamically create a RuntimeLoader
$twig->addRuntimeLoader(new class() implements RuntimeLoaderInterface {
public function load($class)
{
if (\Ocubom\Twig\Extension\SvgRuntime::class === $class) {
return new \Ocubom\Twig\Extension\SvgRuntime(
new \Ocubom\Twig\Extension\Svg\Provider\FileSystem\FileSystemLoader($paths)
);
}
if (\Ocubom\Twig\Extension\Svg\Provider\FontAwesome\FontAwesomeRuntime::class === $class) {
return new \Ocubom\Twig\Extension\Svg\Provider\FontAwesome\FontAwesomeRuntime(
new \Ocubom\Twig\Extension\Svg\Provider\FontAwesome\FontAwesomeLoader($paths)
);
}
if (\Ocubom\Twig\Extension\Svg\Provider\Iconify\IconifyRuntime::class === $class) {
return new \Ocubom\Twig\Extension\Svg\Provider\Iconify\IconifyRuntime(
new \Ocubom\Twig\Extension\Svg\Provider\Iconify\IconifyLoader($paths)
);
}
return null;
}
});
new \Ocubom\Twig\Extension\SvgRuntime(
new \Ocubom\Twig\Extension\Svg\Provider\FileSystem\FileSystemLoader(
new \Ocubom\Twig\Extension\Svg\Util\PathCollection(
'first/search/path',
'second/search/path',
)
)
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.