當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。