1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-18 10:51:21 +02:00

Flextype Core: Snippets Twig Extension added #117

This commit is contained in:
Awilum
2019-06-11 21:50:01 +03:00
parent a6fc059854
commit 2a3ee7c1ec
2 changed files with 49 additions and 0 deletions

View File

@@ -209,6 +209,9 @@ $flextype['view'] = function ($container) {
// Add Global Shortcodes Twig Extension
$view->addExtension(new ShortcodesTwigExtension($container));
// Add Global Snippets Twig Extension
$view->addExtension(new SnippetsTwigExtension($container));
// Return view
return $view;
};

View File

@@ -0,0 +1,46 @@
<?php
/**
* @package Flextype
*
* @author Sergey Romanenko <hello@romanenko.digital>
* @link http://romanenko.digital
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flextype;
class SnippetsTwigExtension extends \Twig_Extension
{
/**
* Flextype Dependency Container
*/
private $flextype;
/**
* Constructor
*/
public function __construct($flextype)
{
$this->flextype = $flextype;
}
/**
* Callback for twig.
*
* @return array
*/
public function getFunctions()
{
return [
new \Twig_SimpleFunction('snippet', [$this, 'snippet'])
];
}
public function snippet(string $id)
{
return $this->flextype['snippets']->display($id);
}
}