<?php
namespace App\TwigExtension;
class IsLoggedIn extends \Slim\Views\TwigExtension
{
public function __construct()
{
}
public function getName()
{
return 'isLoggedIn';
}
public function getFunctions()
{
return [
new \Twig_SimpleFunction('isLoggedIn', array($this, 'isLoggedIn'))
];
}
public function isLoggedIn ()
{
return \App\Helper\Acl::isLoggedIn();
}
}
-------------------------------------------------------------------------------------------
Then in dependencies.php add the IsLoggedIn() extension to the Twig setup section:
$container['view'] = function ($c) {
$settings = $c->get ('settings');
$view = new \Slim\Views\Twig ($settings['view']['template_path'], $settings['view']['twig']);
// Add extensions
$view->addExtension (new Slim\Views\TwigExtension($c->get ('router'), $c->get ('request')->getUri ()));
$view->addExtension (new Twig_Extension_Debug());
$view->addExtension (new App\TwigExtension\IsLoggedIn());
$view['settings'] = $settings; // Do we need this?
return $view;
};