本文整理汇总了PHP中Twig_Loader_Filesystem::setPaths方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Loader_Filesystem::setPaths方法的具体用法?PHP Twig_Loader_Filesystem::setPaths怎么用?PHP Twig_Loader_Filesystem::setPaths使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_Loader_Filesystem
的用法示例。
在下文中一共展示了Twig_Loader_Filesystem::setPaths方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setTwigLoaderPaths
/**
* @see AbstractTheme::setTwigLoaderPaths()
*
* @param \Twig_Loader_Filesystem $loader
*/
protected function setTwigLoaderPaths(\Twig_Loader_Filesystem $loader)
{
$gantry = static::gantry();
/** @var UniformResourceLocator $locator */
$locator = $gantry['locator'];
$loader->setPaths($locator->findResources('gantry-engine://twig'));
$loader->setPaths($locator->findResources('gantry-pages://'), 'pages');
$loader->setPaths($locator->findResources('gantry-positions://'), 'positions');
parent::setTwigLoaderPaths($loader);
}
示例2: renderer
public function renderer()
{
if (!$this->renderer) {
$gantry = \Gantry\Framework\Gantry::instance();
/** @var UniformResourceLocator $locator */
$locator = $gantry['locator'];
$loader = new \Twig_Loader_Filesystem($locator->findResources('gantry-engine://twig'));
$loader->setPaths($locator->findResources('gantry-pages://'), 'pages');
$loader->setPaths($locator->findResources('gantry-positions://'), 'positions');
$params = array('cache' => $locator('gantry-cache://twig', true, true), 'debug' => true, 'auto_reload' => true, 'autoescape' => 'html');
$twig = new \Twig_Environment($loader, $params);
$this->add_to_twig($twig);
$this->renderer = $twig;
}
return $this->renderer;
}
示例3: getTwig
protected function getTwig()
{
$options = ['cache' => false, 'strict_variables' => true];
$loader = new \Twig_Loader_Filesystem();
$loader->setPaths($this->skeletonDirs);
return new \Twig_Environment($loader, $options);
}
示例4: renderFile
/**
* This renders a file based on the $file and sf_type
*
* @param string $file the fullpath to the template file
* @return string
*/
protected function renderFile($file)
{
if (sfConfig::get('sf_logging_enabled', false)) {
$this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Render "%s".', $file))));
}
$this->loader->setPaths((array) realpath(dirname($file)));
return $this->twig->loadTemplate(basename($file))->render($this->getAttributeHolderVariables());
}
示例5: setTwigLoaderPaths
/**
* @see AbstractTheme::setTwigLoaderPaths()
*
* @param \Twig_Loader_Filesystem $loader
*/
protected function setTwigLoaderPaths(\Twig_Loader_Filesystem $loader)
{
$gantry = static::gantry();
/** @var UniformResourceLocator $locator */
$locator = $gantry['locator'];
$loader->setPaths($locator->findResources('gantry-admin://templates'));
$loader->setPaths($locator->findResources('gantry-admin://templates'), 'gantry-admin');
}
示例6: renderFile
/**
* This renders a file based on the $file and sf_type.
*
* @param string $file the fullpath to the template file
*
* @return string
*/
protected function renderFile($file)
{
if (sfConfig::get('sf_logging_enabled', false)) {
$this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Render "%s"', $file))));
}
$this->loader->setPaths((array) realpath(dirname($file)));
$event = $this->dispatcher->filter(new sfEvent($this, 'template.filter_parameters'), $this->attributeHolder->getAll());
return $this->twig->loadTemplate(basename($file))->render($event->getReturnValue());
}
示例7: setTwigLoaderPaths
/**
* @see AbstractTheme::setTwigLoaderPaths()
*
* @param \Twig_Loader_Filesystem $loader
*/
protected function setTwigLoaderPaths(\Twig_Loader_Filesystem $loader)
{
$gantry = static::gantry();
/** @var UniformResourceLocator $locator */
$locator = $gantry['locator'];
$paths = $locator->mergeResources(['gantry-theme://templates', 'gantry-engine://templates']);
// TODO: right now we are replacing all paths; we need to do better, but there are some issues with this call.
$loader->setPaths($paths);
parent::setTwigLoaderPaths($loader);
}
示例8: setNamespaces
public function setNamespaces(\Silex\Application $app)
{
$namespaces = $this->getNamespaces($app);
$app['twig.loader.filesystem'] = $app->share(function ($app) use($namespaces) {
$loader = new \Twig_Loader_Filesystem($app['twig.path']);
foreach ($namespaces as $ns => $path) {
$loader->setPaths($path, $ns);
}
return $loader;
});
}
示例9: load_twig
function load_twig()
{
global $twig, $config;
require 'lib/Twig/Autoloader.php';
Twig_Autoloader::register();
Twig_Autoloader::autoload('Twig_Extensions_Node_Trans');
Twig_Autoloader::autoload('Twig_Extensions_TokenParser_Trans');
Twig_Autoloader::autoload('Twig_Extensions_Extension_I18n');
Twig_Autoloader::autoload('Twig_Extensions_Extension_Tinyboard');
$loader = new Twig_Loader_Filesystem($config['dir']['template']);
$loader->setPaths($config['dir']['template']);
$twig = new Twig_Environment($loader, array('autoescape' => false, 'cache' => is_writable('templates') && (!is_dir('templates/cache') || is_writable('templates/cache')) ? "{$config['dir']['template']}/cache" : false, 'debug' => $config['debug']));
$twig->addExtension(new Twig_Extensions_Extension_Tinyboard());
$twig->addExtension(new Twig_Extensions_Extension_I18n());
}
示例10: testPaths
public function testPaths()
{
$basePath = dirname(__FILE__) . '/Fixtures';
$loader = new Twig_Loader_Filesystem(array($basePath . '/normal', $basePath . '/normal_bis'));
$loader->setPaths(array($basePath . '/named', $basePath . '/named_bis'), 'named');
$loader->addPath($basePath . '/named_ter', 'named');
$loader->addPath($basePath . '/normal_ter');
$loader->prependPath($basePath . '/normal_final');
$loader->prependPath($basePath . '/named_final', 'named');
$this->assertEquals(array($basePath . '/normal_final', $basePath . '/normal', $basePath . '/normal_bis', $basePath . '/normal_ter'), $loader->getPaths());
$this->assertEquals(array($basePath . '/named_final', $basePath . '/named', $basePath . '/named_bis', $basePath . '/named_ter'), $loader->getPaths('named'));
$this->assertEquals("path (final)\n", $loader->getSource('index.html'));
$this->assertEquals("path (final)\n", $loader->getSource('@__main__/index.html'));
$this->assertEquals("named path (final)\n", $loader->getSource('@named/index.html'));
}
示例11: testPaths
public function testPaths()
{
$basePath = __DIR__ . '/Fixtures';
$loader = new Twig_Loader_Filesystem(array($basePath . '/normal', $basePath . '/normal_bis'));
$loader->setPaths(array($basePath . '/named', $basePath . '/named_bis'), 'named');
$loader->addPath($basePath . '/named_ter', 'named');
$loader->addPath($basePath . '/normal_ter');
$loader->prependPath($basePath . '/normal_final');
$loader->prependPath($basePath . '/named/../named_quater', 'named');
$loader->prependPath($basePath . '/named_final', 'named');
$this->assertEquals(array($basePath . '/normal_final', $basePath . '/normal', $basePath . '/normal_bis', $basePath . '/normal_ter'), $loader->getPaths());
$this->assertEquals(array($basePath . '/named_final', $basePath . '/named/../named_quater', $basePath . '/named', $basePath . '/named_bis', $basePath . '/named_ter'), $loader->getPaths('named'));
$this->assertEquals(realpath($basePath . '/named_quater/named_absolute.html'), realpath($loader->getCacheKey('@named/named_absolute.html')));
$this->assertEquals("path (final)\n", $loader->getSource('index.html'));
$this->assertEquals("path (final)\n", $loader->getSource('@__main__/index.html'));
$this->assertEquals("named path (final)\n", $loader->getSource('@named/index.html'));
}
示例12: testPaths
/**
* @dataProvider getBasePaths
*/
public function testPaths($basePath)
{
$loader = new Twig_Loader_Filesystem(array($basePath . '/normal', $basePath . '/normal_bis'));
$loader->setPaths(array($basePath . '/named', $basePath . '/named_bis'), 'named');
$loader->addPath($basePath . '/named_ter', 'named');
$loader->addPath($basePath . '/normal_ter');
$loader->prependPath($basePath . '/normal_final');
$loader->prependPath($basePath . '/named/../named_quater', 'named');
$loader->prependPath($basePath . '/named_final', 'named');
$this->assertEquals(array($basePath . '/normal_final', $basePath . '/normal', $basePath . '/normal_bis', $basePath . '/normal_ter'), $loader->getPaths());
$this->assertEquals(array($basePath . '/named_final', $basePath . '/named/../named_quater', $basePath . '/named', $basePath . '/named_bis', $basePath . '/named_ter'), $loader->getPaths('named'));
// do not use realpath here as it would make the test unuseful
$this->assertEquals(str_replace('\\', '/', $basePath . '/named_quater/named_absolute.html'), str_replace('\\', '/', $loader->getCacheKey('@named/named_absolute.html')));
$this->assertEquals("path (final)\n", $loader->getSource('index.html'));
$this->assertEquals("path (final)\n", $loader->getSource('@__main__/index.html'));
$this->assertEquals("named path (final)\n", $loader->getSource('@named/index.html'));
}
示例13: setTemplatesPaths
/**
* Sets the paths where templates are stored.
*
* @param string|array $paths A path or an array of paths where to look for templates.
* @param bool $overrideBaseDir If true a path can be outside themes base directory.
*
* @return Twig
*
* @since 1.0
*/
public function setTemplatesPaths($paths, $overrideBaseDir = false)
{
if (!is_array($paths)) {
$paths = array($paths);
}
foreach ($paths as $path) {
if ($overrideBaseDir) {
$this->templatesPaths[] = $path;
} else {
$this->templatesPaths[] = $this->config['templates_base_dir'] . $path;
}
}
// Reset the paths if needed.
if (is_object($this->twigLoader)) {
try {
$this->twigLoader->setPaths($this->templatesPaths);
} catch (\Twig_Error_Loader $e) {
echo $e->getRawMessage();
}
}
return $this;
}
示例14: setViewPaths
public function setViewPaths(array $paths = array())
{
$this->loader->setPaths($paths);
}
示例15: selectTheme
public function selectTheme($theme)
{
$this->themeName = $theme;
$this->selectThemePath();
$this->loader->setPaths($this->dir() . $this->themePath);
}