diff options
author | Igor Scheller <igor.scheller@igorshp.de> | 2018-09-10 14:40:33 +0200 |
---|---|---|
committer | Igor Scheller <igor.scheller@igorshp.de> | 2018-09-10 14:40:33 +0200 |
commit | 4bf3a68f43e4fcea34fe0a16cb3e1eecb97d332a (patch) | |
tree | 736cdc6a8df17b12d9f18312eaf09637298caabf /src/Renderer/Twig/Extensions | |
parent | 222c9fed7d4ca2b3b44c05907fbb7080c1efd342 (diff) |
Fixed assets rendering
Diffstat (limited to 'src/Renderer/Twig/Extensions')
-rw-r--r-- | src/Renderer/Twig/Extensions/Assets.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/Renderer/Twig/Extensions/Assets.php b/src/Renderer/Twig/Extensions/Assets.php new file mode 100644 index 00000000..2cdfb0fd --- /dev/null +++ b/src/Renderer/Twig/Extensions/Assets.php @@ -0,0 +1,42 @@ +<?php + +namespace Engelsystem\Renderer\Twig\Extensions; + +use Engelsystem\Http\UrlGenerator; +use Twig_Extension as TwigExtension; +use Twig_Function as TwigFunction; + +class Assets extends TwigExtension +{ + /** @var UrlGenerator */ + protected $urlGenerator; + + /** + * @param UrlGenerator $urlGenerator + */ + public function __construct(UrlGenerator $urlGenerator) + { + $this->urlGenerator = $urlGenerator; + } + + /** + * @return TwigFunction[] + */ + public function getFunctions() + { + return [ + new TwigFunction('asset', [$this, 'getAsset']), + ]; + } + + /** + * @param string $path + * @return UrlGenerator|string + */ + public function getAsset($path) + { + $path = ltrim($path, '/'); + + return $this->urlGenerator->to('/' . $path); + } +} |