当前位置: 首页>>代码示例>>PHP>>正文


PHP Twig_Environment::addGlobal方法代码示例

本文整理汇总了PHP中Twig_Environment::addGlobal方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Environment::addGlobal方法的具体用法?PHP Twig_Environment::addGlobal怎么用?PHP Twig_Environment::addGlobal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Twig_Environment的用法示例。


在下文中一共展示了Twig_Environment::addGlobal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getTwigEnvironment

 /**
  * Sets up Twig ready for use and returns it
  * @return \Twig_Environment
  */
 protected function getTwigEnvironment()
 {
     /**
      * Get the config
      * @var \snb\config\ConfigInterface $config
      */
     $config = $this->container->get('config');
     $kernel = $this->container->get('kernel');
     // Find the cache path
     $cachePath = $config->get('twig.cache', ':/cache');
     // Use our loader the know how to map resource names to filenames
     $loader = new TwigFileLoader($this->container);
     // use the default environment. Should pass settings over from the config
     $twig = new \Twig_Environment($loader, array('cache' => $kernel->findPath($cachePath), 'debug' => $kernel->isDebug()));
     // Add the dump command (only works when debug is true)
     $twig->addExtension(new \Twig_Extension_Debug());
     // Add the app as a global...
     $twig->addGlobal('app', $kernel);
     // Add all the extensions that have been registered with the service provider
     $globals = $this->container->getMatching('twig.global.*');
     foreach ($globals as $global) {
         if ($global instanceof ViewGlobalInterface) {
             $twig->addGlobal($global->getGlobalName(), $global);
         }
     }
     // Add all the extensions that have been registered with the service provider
     $extensions = $this->container->getMatching('twig.extension.*');
     foreach ($extensions as $ext) {
         $twig->addExtension($ext);
     }
     return $twig;
 }
开发者ID:rikh42,项目名称:band-snb,代码行数:36,代码来源:TwigView.php

示例2: view

 public static function view($modules = NULL)
 {
     include_once __ROOT__ . 'vendor/autoload.php';
     $views = __VIEWS__;
     if (__ENV_MODE__ == "dev") {
         $cache = false;
     } else {
         $cache = true;
     }
     $loader = new \Twig_Loader_Filesystem($views);
     // Dossier contenant les templates
     if ($cache) {
         $twig = new \Twig_Environment($loader, array('debug' => false, 'cache' => $views . '/cache/', 'auto_reload' => true));
     } else {
         $twig = new \Twig_Environment($loader, array('debug' => true));
     }
     $twig->addExtension(new \Twig_Extensions_Extension_Text());
     $twig->addExtension(new \Twig_Extensions_Extension_I18n());
     $twig->addExtension(new \Twig_Extensions_Extension_Intl());
     $twig->addExtension(new \Twig_Extensions_Extension_Array());
     $twig->addExtension(new \Twig_Extensions_Extension_Date());
     $twig->addGlobal('app_name', __NAME_APPLICATION__);
     $path = array('views' => $views, 'url' => __URL_LOCAL__, 'bootstrap' => __BOOTSTRAP__);
     $twig->addGlobal('path', $path);
     $route = array('only' => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
     $twig->addGlobal('route', $route);
     return $twig;
 }
开发者ID:jodevweb,项目名称:Fmkj,代码行数:28,代码来源:BaseController.class.php

示例3: getTwig

 public function getTwig($configuration)
 {
     $templateDir = $this->getRootPath() . '/src/DavM85/BusFactor/Resources/views';
     $loader = new \Twig_Loader_Filesystem($templateDir);
     $twig = new \Twig_Environment($loader, array());
     $twig->addGlobal('rootPath', $configuration['targetDir'] . '/');
     $twig->addGlobal('lower', $configuration['lower_threshold']);
     $twig->addGlobal('higher', $configuration['higher_threshold']);
     $filter = new \Twig_SimpleFilter('level', function ($percent) use($configuration) {
         $lower = $configuration['lower_threshold'];
         $higher = $configuration['higher_threshold'];
         if ($percent == 0) {
             return '';
         } elseif ($percent < $lower) {
             return 'success';
         } elseif ($percent >= $lower && $percent < $higher) {
             return 'warning';
         } else {
             return 'danger';
         }
     });
     $twig->addFilter($filter);
     // @todo dont know why I left that here
     $common = array('id' => '', 'full_path' => '', 'path_to_root' => '', 'breadcrumbs' => '', 'date' => '', 'version' => '', 'runtime_name' => '', 'runtime_version' => '', 'runtime_link' => '', 'generator' => '', 'low_upper_bound' => '', 'high_lower_bound' => '');
     return $twig;
 }
开发者ID:dav-m85,项目名称:busfactor,代码行数:26,代码来源:GenerateCommand.php

示例4: setUp

 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     if (!in_array($this->type, array('form', 'filter'))) {
         throw new \Exception('Please override $this->type in your test class specifying template to use (either form or filter)');
     }
     $rendererEngine = new TwigRendererEngine(array($this->type . '_admin_fields.html.twig'));
     $csrfManagerClass = interface_exists('Symfony\\Component\\Security\\Csrf\\CsrfTokenManagerInterface') ? 'Symfony\\Component\\Security\\Csrf\\CsrfTokenManagerInterface' : 'Symfony\\Component\\Form\\Extension\\Csrf\\CsrfProvider\\CsrfProviderInterface';
     $renderer = new TwigRenderer($rendererEngine, $this->getMock($csrfManagerClass));
     $this->extension = new FormExtension($renderer);
     $twigPaths = array(__DIR__ . '/../../../Resources/views/Form');
     //this is ugly workaround for different build strategies and, possibly,
     //different TwigBridge installation directories
     if (is_dir(__DIR__ . '/../../../vendor/symfony/twig-bridge/Resources/views/Form')) {
         $twigPaths[] = __DIR__ . '/../../../vendor/symfony/twig-bridge/Resources/views/Form';
     } elseif (is_dir(__DIR__ . '/../../../vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form')) {
         $twigPaths[] = __DIR__ . '/../../../vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form';
     } else {
         $twigPaths[] = __DIR__ . '/../../../../../symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form';
     }
     $loader = new StubFilesystemLoader($twigPaths);
     $this->environment = new \Twig_Environment($loader, array('strict_variables' => true));
     $this->environment->addGlobal('sonata_admin', $this->getSonataAdmin());
     $this->environment->addExtension(new TranslationExtension(new StubTranslator()));
     $this->environment->addExtension($this->extension);
     $this->extension->initRuntime($this->environment);
 }
开发者ID:vincenttouzet,项目名称:SonataAdminBundle,代码行数:30,代码来源:BaseWidgetTest.php

示例5: before

 /**
  * @return array[string => mixed]
  */
 public static function before()
 {
     $user = null;
     // initialize session
     Session::init();
     // setup twig
     $twig = new \Twig_Environment(new \Twig_Loader_Filesystem());
     $twig->getLoader()->addPath(__DIR__ . '/Twig');
     $twig->addGlobal('asset', Settings::load('settings')->get('asset-url'));
     $twig->addGlobal('base_url', NekoPHP::getBaseUrl());
     // add the current user object to twig, if it exists
     $user_id = Session::get('user_id');
     // set the user if a user_id is set
     if ($user_id > 0) {
         $user = new \NekoPHP\Modules\User\Models\User($user_id);
         $twig->addGlobal('cuser', $user);
     }
     // add one-time alerts
     foreach (['success', 'info', 'warning', 'error'] as $alert) {
         if (Session::existsOnce($alert)) {
             $twig->addGlobal('alert_' . $alert, Session::getOnce($alert));
         }
     }
     return ['cuser' => $user, 'twig' => $twig];
 }
开发者ID:scriptkitties,项目名称:NekoPHP,代码行数:28,代码来源:Shared.php

示例6: setUp

 protected function setUp()
 {
     if (!class_exists('Symfony\\Component\\Locale\\Locale')) {
         $this->markTestSkipped('The "Locale" component is not available');
     }
     if (!class_exists('Symfony\\Component\\EventDispatcher\\EventDispatcher')) {
         $this->markTestSkipped('The "EventDispatcher" component is not available');
     }
     if (!class_exists('Symfony\\Component\\Form\\Form')) {
         $this->markTestSkipped('The "Form" component is not available');
     }
     if (!class_exists('Twig_Environment')) {
         $this->markTestSkipped('Twig is not available.');
     }
     parent::setUp();
     $rendererEngine = new TwigRendererEngine(array('form_div_layout.html.twig', 'custom_widgets.html.twig'));
     $renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\\Component\\Form\\Extension\\Csrf\\CsrfProvider\\CsrfProviderInterface'));
     $this->extension = new FormExtension($renderer);
     $loader = new StubFilesystemLoader(array(__DIR__ . '/../../Resources/views/Form', __DIR__));
     $environment = new \Twig_Environment($loader, array('strict_variables' => true));
     $environment->addExtension(new TranslationExtension(new StubTranslator()));
     $environment->addGlobal('global', '');
     // the value can be any template that exists
     $environment->addGlobal('dynamic_template_name', 'child_label');
     $environment->addExtension($this->extension);
     $this->extension->initRuntime($environment);
 }
开发者ID:rolfmadsen,项目名称:dummy_alma,代码行数:27,代码来源:FormExtensionDivLayoutTest.php

示例7: __construct

 public function __construct(\Twig_Environment $twig = null, array $config = array())
 {
     if ($twig) {
         $this->twig = $twig;
         $this->twig->addGlobal('ctrl_rad_templates', $config['templates']);
     }
 }
开发者ID:ctrl-f5,项目名称:ctrl-rad-bundle,代码行数:7,代码来源:CtrlRadExtension.php

示例8: onKernelRequest

 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if (!$event->isMasterRequest() || '/' !== $request->getPathInfo()) {
         return;
     }
     $this->twig->addGlobal('random_quote_event', $this->quoteRepository->findRandom());
 }
开发者ID:steviebiddles,项目名称:phpbelfast-meetup14,代码行数:11,代码来源:RandomQuoteListener.php

示例9: addGlobal

 /**
  * 新增模板所需要的一些常量
  * @param \Twig_Environment $twig
  */
 protected function addGlobal(\Twig_Environment $twig)
 {
     //添加常用的全局变量
     $twig->addGlobal('__CSS__', BASEDIR . '/App/Public/css');
     $twig->addGlobal('__JS__', BASEDIR . '/App/Public/js');
     $twig->addGlobal('__IMAGE__', BASEDIR . '/App/Public/image');
     $twig->addGlobal('STATIC_PATH', '/public');
     $twig->addGlobal('IMG_PATH', '/public/images');
 }
开发者ID:TeamOfMalaysia,项目名称:H,代码行数:13,代码来源:Response.php

示例10: __construct

 /**
  * Initialize a new View
  *
  * @param $file
  */
 public function __construct($file, $data = null)
 {
     $this->file = $file;
     $this->data = $data;
     $twigLoader = new Twig_Loader_Filesystem(INC_ROOT . '/app/views', '__main__');
     $this->twig = new Twig_Environment($twigLoader, ['cache' => INC_ROOT . '/app/cache']);
     $this->twig->addGlobal('ASSET_ROOT', ASSET_ROOT);
     $this->twig->addGlobal('HTTP_ROOT', HTTP_ROOT);
 }
开发者ID:creativewild,项目名称:ts3Chan,代码行数:14,代码来源:View.php

示例11: render

 protected function render($array = [])
 {
     $this->twig->addGlobal("request_path", $this->requestStack->getCurrentRequest()->getPathInfo());
     $calleeClass = get_called_class();
     $calleeMethod = debug_backtrace()[1]['function'];
     $exploded = explode("\\", $calleeClass);
     $calleeFinalPart = implode("/", array_merge(array_slice($exploded, 3, count($exploded) - 4), [str_replace("Controller", "", end($exploded))]));
     $templateFilename = $calleeFinalPart . "/" . $calleeMethod . ".twig";
     return $this->twig->render($templateFilename, $array);
 }
开发者ID:Dolondro,项目名称:rargh,代码行数:10,代码来源:AbstractController.php

示例12: __Construct

 /**
  * Constructor
  *
  * @param string $templateDir
  * @param bool $cacheDir
  *
  * @throws TemplateDirectoryNotFoundException
  */
 public function __Construct($templateDir, $cacheDir = false)
 {
     if (realpath($templateDir) === false) {
         throw new TemplateDirectoryNotFoundException(sprintf('template directory not found in "%s"', $templateDir));
     }
     $this->application = Application::getInstance();
     $this->loader = new \Twig_Loader_Filesystem($templateDir);
     $this->template = new \Twig_Environment($this->loader, array('cache' => $cacheDir, 'auto_reload' => true, 'strict_variables' => true));
     $this->template->addGlobal('app', $this->application);
 }
开发者ID:zanra,项目名称:framework,代码行数:18,代码来源:Template.php

示例13: getTwig

 public static function getTwig()
 {
     if (!self::$twig) {
         \Twig_Autoloader::register();
         $cache = Config::get('cache') ? Config::get('cache') . '/' : false;
         $loader = new \Twig_Loader_Filesystem(Config::get('views') . '/');
         $twig = new \Twig_Environment($loader, array('cache' => $cache, 'debug' => Config::get('debug')));
         // Add globals
         $twig->addGlobal('session', Session::getInstance());
         $twig->addGlobal('url', new URL());
         self::$twig = $twig;
     }
     return self::$twig;
 }
开发者ID:alterfw,项目名称:ampersand,代码行数:14,代码来源:Render.php

示例14: EjecutarPlantillaDesarrollo

 /**
  * Metodo Privado
  * EjecutarPlantillaDesarrollo($Parametros)
  * 
  * Carga la plantilla correspondiente
  * @access private
  */
 private function EjecutarPlantillaDesarrollo($Parametros = array())
 {
     self::ValidarEjecutarTwig();
     $TwigLoader = new Twig_Loader_Filesystem(implode(DIRECTORY_SEPARATOR, array(__SysNeuralFileRootLibNeural__, self::$FolderErrores, self::$FolderAlertas)));
     $TwigEnvironment = new Twig_Environment($TwigLoader, array('charset' => 'UTF-8'));
     if (defined('APPNEURALPHPHOST') == true) {
         $TwigEnvironment->addGlobal('NeuralRutaApp', implode('/', array(__NeuralUrlRaiz__)));
         $TwigEnvironment->addGlobal('NeuralRutaWebPublico', implode('/', array(__NeuralUrlRaiz__, 'WebRoot', 'ErroresWeb')));
     } else {
         $TwigEnvironment->addGlobal('NeuralRutaBase', __NeuralUrlRaiz__);
         $TwigEnvironment->addGlobal('NeuralRutaWebPublico', implode('/', array(__NeuralUrlRaiz__, 'Web')));
     }
     echo $TwigEnvironment->render($Parametros['Plantilla'], array('Titulo' => $Parametros['Titulo'], 'Informacion' => $Parametros['Informacion'], 'Aplicacion' => $Parametros['Aplicacion'], 'Modulo' => $Parametros['Modulo'], 'Controlador' => $Parametros['Controlador'], 'Metodo' => $Parametros['Metodo'], 'Server' => $_SERVER, 'PHP' => array('VERSION' => phpversion(), 'MEMORY' => memory_get_usage(), 'OS' => php_uname('s'), 'MACHINE' => php_uname('m'), 'NAME_SERVER' => gethostbyaddr($_SERVER['SERVER_ADDR']))));
 }
开发者ID:alejofix,项目名称:Mejoramiento,代码行数:21,代码来源:ErrorDesarrollo.php

示例15: setUp

 protected function setUp()
 {
     parent::setUp();
     $loader = new StubFilesystemLoader(array(__DIR__ . '/../../Resources/views/Form', __DIR__ . '/Fixtures/templates/form'));
     $environment = new \Twig_Environment($loader, array('strict_variables' => true));
     $environment->addExtension(new TranslationExtension(new StubTranslator()));
     $environment->addGlobal('global', '');
     // the value can be any template that exists
     $environment->addGlobal('dynamic_template_name', 'child_label');
     $environment->addExtension(new FormExtension());
     $rendererEngine = new TwigRendererEngine(array('form_div_layout.html.twig', 'custom_widgets.html.twig'), $environment);
     $this->renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\\Component\\Security\\Csrf\\CsrfTokenManagerInterface'));
     $this->registerTwigRuntimeLoader($environment, $this->renderer);
 }
开发者ID:blazarecki,项目名称:symfony,代码行数:14,代码来源:FormExtensionDivLayoutTest.php


注:本文中的Twig_Environment::addGlobal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。