當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Twig_Environment類代碼示例

本文整理匯總了PHP中Twig_Environment的典型用法代碼示例。如果您正苦於以下問題:PHP Twig_Environment類的具體用法?PHP Twig_Environment怎麽用?PHP Twig_Environment使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Twig_Environment類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getTemplate

 private function getTemplate($template, $container)
 {
     $loader = new \Twig_Loader_Array(array('index' => $template));
     $twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
     $twig->addExtension(new DataGridExtension($container));
     return $twig->loadTemplate('index');
 }
開發者ID:firano,項目名稱:datagrid-bundle,代碼行數:7,代碼來源:DataGridExtensionTest.php

示例2: renderBreadcrumbs

 public function renderBreadcrumbs(\Twig_Environment $twig, Breadcrumbs $breadcrumbs = null, $template = '@Breadcrumbs/breadcrumbs.html.twig')
 {
     if (null === $breadcrumbs) {
         $breadcrumbs = $this->breadcrumbsBuilder->createFromRequest();
     }
     return $twig->render($template, array('breadcrumbs' => $breadcrumbs));
 }
開發者ID:yceruto,項目名稱:breadcrumbs-bundle,代碼行數:7,代碼來源:BreadcrumbsExtension.php

示例3: loadTemplate

 public function loadTemplate($file, $variables)
 {
     $loader = new \Twig_Loader_Filesystem(\AHContentBlockerServer\TEMPLATES_PATH_MAIN);
     $twig = new \Twig_Environment($loader, array('cache' => \AHContentBlockerServer\TEMPLATES_PATH_CACHE));
     $loginTemplate = $twig->loadTemplate($file);
     return $loginTemplate->render($variables);
 }
開發者ID:alihamze,項目名稱:ContentBlocker,代碼行數:7,代碼來源:AHTemplateLoader.php

示例4: __construct

    /**
     * Constructor
     *
     * @param string $tmplPath
     * @param array $extraParams
     * @return void
     */
    public function __construct($tmplPath = null, $extraParams = array())
    {
        Twig_Autoloader::register();
        $loader = new Twig_Loader_Filesystem($tmplPath);
        $cache_path = (array_key_exists('cache_path', $extraParams))
            ? $extraParams['cache_path']
            : '../cache'
            ;
        $view = new Twig_Environment($loader,
            array(
                'cache' => $cache_path,
                'auto_reload' => true,
            )
        );
        $escaper = new Twig_Extension_Escaper(true);
        $view->addExtension($escaper);

        $this->_twig = $view;

        if (null !== $tmplPath) {
            $this->setScriptPath($tmplPath);
        }

        foreach ($extraParams as $key => $value) {
            $this->_twig->{$key} = $value;
        }
    }
開發者ID:junichiro,項目名稱:zend-view-twig,代碼行數:34,代碼來源:Twig.php

示例5: getTests

 public function getTests()
 {
     $environment = new Twig_Environment();
     $environment->addFunction('foo', new Twig_Function_Function('foo', array()));
     $environment->addFunction('bar', new Twig_Function_Function('bar', array('needs_environment' => true)));
     $environment->addFunction('foofoo', new Twig_Function_Function('foofoo', array('needs_context' => true)));
     $environment->addFunction('foobar', new Twig_Function_Function('foobar', array('needs_environment' => true, 'needs_context' => true)));
     $tests = array();
     $node = $this->createFunction('foo');
     $tests[] = array($node, 'foo()', $environment);
     $node = $this->createFunction('foo', array(new Twig_Node_Expression_Constant('bar', 1), new Twig_Node_Expression_Constant('foobar', 1)));
     $tests[] = array($node, 'foo("bar", "foobar")', $environment);
     $node = $this->createFunction('bar');
     $tests[] = array($node, 'bar($this->env)', $environment);
     $node = $this->createFunction('bar', array(new Twig_Node_Expression_Constant('bar', 1)));
     $tests[] = array($node, 'bar($this->env, "bar")', $environment);
     $node = $this->createFunction('foofoo');
     $tests[] = array($node, 'foofoo($context)', $environment);
     $node = $this->createFunction('foofoo', array(new Twig_Node_Expression_Constant('bar', 1)));
     $tests[] = array($node, 'foofoo($context, "bar")', $environment);
     $node = $this->createFunction('foobar');
     $tests[] = array($node, 'foobar($this->env, $context)', $environment);
     $node = $this->createFunction('foobar', array(new Twig_Node_Expression_Constant('bar', 1)));
     $tests[] = array($node, 'foobar($this->env, $context, "bar")', $environment);
     // named arguments
     $node = $this->createFunction('date', array('timezone' => new Twig_Node_Expression_Constant('America/Chicago', 1), 'date' => new Twig_Node_Expression_Constant(0, 1)));
     $tests[] = array($node, 'twig_date_converter($this->env, 0, "America/Chicago")');
     return $tests;
 }
開發者ID:simonjodet,項目名稱:twig,代碼行數:29,代碼來源:FunctionTest.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_table_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', '');
     $environment->addExtension($this->extension);
     $this->extension->initRuntime($environment);
 }
開發者ID:tejdeeps,項目名稱:tejcs.com,代碼行數:25,代碼來源:FormExtensionTableLayoutTest.php

示例7: 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

示例8: testEscaping

 /**
  * Tests the escaping
  *
  * @dataProvider providerTestEscaping
  */
 public function testEscaping($template, $expected)
 {
     $twig = new \Twig_Environment(NULL, array('debug' => TRUE, 'cache' => FALSE, 'autoescape' => TRUE, 'optimizations' => 0));
     $twig->addExtension((new TwigExtension())->setGenerators($this->getMock('Drupal\\Core\\Routing\\UrlGeneratorInterface')));
     $nodes = $twig->parse($twig->tokenize($template));
     $this->assertSame($expected, $nodes->getNode('body')->getNode(0)->getNode('expr') instanceof \Twig_Node_Expression_Filter);
 }
開發者ID:Nikola-xiii,項目名稱:d8intranet,代碼行數:12,代碼來源:TwigExtensionTest.php

示例9: 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

示例10: initRuntime

 public function initRuntime(\Twig_Environment $environment)
 {
     $this->twigEnvironment = $environment;
     $loader = new \Twig_Loader_Filesystem();
     $loader->addPath(__DIR__ . '/../Resorces/views', 'np_navigation');
     $environment->getLoader()->addLoader($loader);
 }
開發者ID:nodepub,項目名稱:navigation,代碼行數:7,代碼來源:NavigationTwigExtension.php

示例11: __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

示例12: createEnvironment

 /**
  * @return \Twig_Environment
  */
 protected function createEnvironment()
 {
     $loader = new \Twig_Loader_Array([]);
     $twig = new \Twig_Environment($loader, ['debug' => true, 'cache' => false, 'autoescape' => false]);
     $twig->addExtension($this->createExtension());
     return $twig;
 }
開發者ID:J-Ben87,項目名稱:enum-bundle,代碼行數:10,代碼來源:EnumExtensionTest.php

示例13: setUp

 public function setUp()
 {
     $this->cmfHelper = $this->getMockBuilder('Symfony\\Cmf\\Bundle\\CoreBundle\\Templating\\Helper\\CmfHelper')->disableOriginalConstructor()->getMock();
     $this->cmfExtension = new CmfExtension($this->cmfHelper);
     $this->env = new \Twig_Environment(new \Twig_Loader_Array(array()));
     $this->env->addExtension($this->cmfExtension);
 }
開發者ID:symfony-cmf,項目名稱:core-bundle,代碼行數:7,代碼來源:CmfExtensionTest.php

示例14: getIconTemplate

 /**
  * @return \Twig_Template
  */
 protected function getIconTemplate(\Twig_Environment $env)
 {
     if ($this->iconTemplate === null) {
         $this->iconTemplate = $env->loadTemplate('@MopaBootstrap/icons.html.twig');
     }
     return $this->iconTemplate;
 }
開發者ID:hirenbhut93,項目名稱:MopaBootstrapBundle,代碼行數:10,代碼來源:IconExtension.php

示例15: extendTwig

 /**
  * Adds the WP-specific filters and functions to the twig environment
  * @param \Twig_Environment $twig_Environment
  */
 private static function extendTwig(\Twig_Environment $twig_Environment)
 {
     $twig_Environment->addFilter(new \Twig_SimpleFilter('__', function ($text, $domain = 'default') {
         return __($text, $domain);
     }));
     $twig_Environment->addExtension(new SlugifyExtension(Slugify::create()));
 }
開發者ID:jmversteeg,項目名稱:jvwp,代碼行數:11,代碼來源:Templates.php


注:本文中的Twig_Environment類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。