当前位置: 首页>>代码示例>>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;未经允许,请勿转载。