Skip to content

Instantly share code, notes, and snippets.

@victorlapshev
Created October 24, 2017 09:48
Show Gist options
  • Select an option

  • Save victorlapshev/b865325be244c8389a7815a641d7274a to your computer and use it in GitHub Desktop.

Select an option

Save victorlapshev/b865325be244c8389a7815a641d7274a to your computer and use it in GitHub Desktop.
<?php
namespace Events;
use Bitrix\Main\Event;
use Bitrix\Main\EventResult;
use Misc\TwigExtension;
class Twig
{
public static function addTwigExtension(Event $e)
{
/** @var \Twig_Environment $engine */
$engine = $e->getParameter(0);
//$engine->addExtension(new TwigExtension() );
$includeFile = new \Twig_SimpleFunction('includeFile', function ($file) {
global $APPLICATION;
ob_start();
$APPLICATION->IncludeFile(INCLUDE_PATH . $file . '.php');
return ob_get_clean();
});
$engine->addFunction('includeFile', $includeFile);
return new EventResult(EventResult::SUCCESS, array($engine));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment