本文整理汇总了PHP中Twig_Environment类的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Environment类的具体用法?PHP Twig_Environment怎么用?PHP Twig_Environment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Twig_Environment类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: template
private function template()
{
$config = new Config($this->registry);
$twigPath = $config->getTWIGPath();
$this->themeUrl = $this->registry->siteUrl . 'themes/' . $this->registry->template . '/';
$this->isAjaxRequest = $this->registry->dispatcher->isAjaxRequest();
require $twigPath;
\Twig_Autoloader::register();
$loader = new \Twig_Loader_Filesystem($this->getTemplate());
$twig = new \Twig_Environment($loader);
$urlFunction = new \Twig_SimpleFunction('url', function ($ctrl_action, $paramsArray = NULL) {
$ctrl_action = explode('/', $ctrl_action);
$controller = $ctrl_action[0] . '/';
$action = $ctrl_action[1] . '/';
$params = '';
if (isset($paramsArray)) {
$params .= '?';
foreach ($paramsArray as $key => $value) {
$params .= $key . '=' . $value;
if (end($paramsArray) != $value) {
$params .= '&';
}
}
}
$url = $this->registry->siteUrl . $controller . $action . $params;
return $url;
});
$twig->addFunction($urlFunction);
$template = $twig->loadTemplate($this->getView());
return $template;
}
开发者ID:arunprasathb,项目名称:KMF-MVC,代码行数:31,代码来源:View.php
示例17: render
public function render($templateName)
{
$loader = new \Twig_Loader_Filesystem("../source/app/templates/");
$twig = new \Twig_Environment($loader, array());
$template = $twig->loadTemplate("{$templateName}.html");
return $template->render(array());
}
开发者ID:professorsloth,项目名称:achat,代码行数:7,代码来源:Twig.php
示例18: register
public function register(Application $app)
{
if (!isset($app['twig'])) {
$app->register(new \Silex\Provider\TwigServiceProvider());
}
// Handlers
$app['twig.handlers'] = $app->share(function (Application $app) {
return new \Pimple(['admin' => $app->share(function () use($app) {
return new AdminHandler($app);
}), 'array' => $app->share(function () use($app) {
return new ArrayHandler($app);
}), 'html' => $app->share(function () use($app) {
return new HtmlHandler($app);
}), 'image' => $app->share(function () use($app) {
return new ImageHandler($app);
}), 'record' => $app->share(function () use($app) {
return new RecordHandler($app);
}), 'text' => $app->share(function () use($app) {
return new TextHandler($app);
}), 'user' => $app->share(function () use($app) {
return new UserHandler($app);
}), 'utils' => $app->share(function () use($app) {
return new UtilsHandler($app);
})]);
});
// Add the Bolt Twig Extension.
$app['twig'] = $app->share($app->extend('twig', function (\Twig_Environment $twig, $app) {
$twig->addExtension(new TwigExtension($app, $app['twig.handlers'], false));
return $twig;
}));
$app['twig.loader.filesystem'] = $app->share($app->extend('twig.loader.filesystem', function ($filesystem, $app) {
$filesystem->addPath($app['resources']->getPath('app/view/twig'), 'bolt');
// @deprecated Since Bolt 2.3 and will be removed in Bolt 3.
$filesystem->addPath($app['resources']->getPath('app/view/twig'));
return $filesystem;
}));
// Twig paths
$app['twig.path'] = function () use($app) {
return $app['config']->getTwigPath();
};
// Twig options
$app['twig.options'] = function () use($app) {
// Should we cache or not?
if ($app['config']->get('general/caching/templates')) {
$cache = $app['resources']->getPath('cache');
} else {
$cache = false;
}
return ['debug' => true, 'cache' => $cache, 'strict_variables' => $app['config']->get('general/strict_variables'), 'autoescape' => true];
};
$app['safe_twig.bolt_extension'] = function () use($app) {
return new TwigExtension($app, $app['twig.handlers'], true);
};
$app['safe_twig'] = $app->share(function ($app) {
$loader = new \Twig_Loader_String();
$twig = new \Twig_Environment($loader);
$twig->addExtension($app['safe_twig.bolt_extension']);
return $twig;
});
}
开发者ID:richardudovich,项目名称:bolt,代码行数:60,代码来源:TwigServiceProvider.php
示例19: render
public function render()
{
$loader = new Twig_Loader_Filesystem(__DIR__ . '/../template/');
$twig = new Twig_Environment($loader, array('debug' => true));
$template = $twig->loadTemplate($this->layout);
return $template->render($this->arrayVar);
}
开发者ID:alsvader,项目名称:percasBlog,代码行数:7,代码来源:AbstractView.class.php
示例20: render
public function render()
{
delete_transient($this->transient_notices);
$loader = new \Twig_Loader_Filesystem($this->paths);
$twig = new \Twig_Environment($loader);
// Add the admin_url() function.
$twig->addFunction('admin_url', new \Twig_SimpleFunction('admin_url', 'admin_url'));
// Add titlecase filter.
$titlecase_filter = new \Twig_SimpleFilter('titlecase', '\\WordPress\\Tabulate\\Text::titlecase');
$twig->addFilter($titlecase_filter);
// Add date and time filters.
$date_filter = new \Twig_SimpleFilter('wp_date_format', '\\WordPress\\Tabulate\\Text::wp_date_format');
$twig->addFilter($date_filter);
$time_filter = new \Twig_SimpleFilter('wp_time_format', '\\WordPress\\Tabulate\\Text::wp_time_format');
$twig->addFilter($time_filter);
// Add strtolower filter.
$strtolower_filter = new \Twig_SimpleFilter('strtolower', function ($str) {
if (is_array($str)) {
return array_map('strtolower', $str);
} else {
return strtolower($str);
}
});
$twig->addFilter($strtolower_filter);
// Enable debugging.
if (WP_DEBUG) {
$twig->enableDebug();
$twig->addExtension(new \Twig_Extension_Debug());
}
// Render the template.
$template = $twig->loadTemplate($this->templateName);
return $template->render($this->data);
}
开发者ID:kcdipesh,项目名称:tabulate,代码行数:33,代码来源:Template.php
注:本文中的Twig_Environment类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论