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:
@@ -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;
|
||||
};
|
||||
|
46
flextype/twig/SnippetsTwigExtension.php
Normal file
46
flextype/twig/SnippetsTwigExtension.php
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user