本文整理汇总了PHP中Twig_Template::getTemplateName方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Template::getTemplateName方法的具体用法?PHP Twig_Template::getTemplateName怎么用?PHP Twig_Template::getTemplateName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_Template
的用法示例。
在下文中一共展示了Twig_Template::getTemplateName方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addTemplate
/**
* @param Template $template
*/
public function addTemplate(Template $template)
{
$this->templates[$template->getTemplateName()] = $template;
/** @var Template $parent */
if ($parent = $template->getParent([])) {
$this->addTemplate($parent);
}
}
示例2: getTemplates
protected function getTemplates(\Twig_Template $template)
{
$names = [];
$names[] = $template->getTemplateName();
if (false !== ($parent = $template->getParent([]))) {
$names = array_merge($names, $this->getTemplates($parent));
}
return $names;
}
示例3: getTemplateSource
private function getTemplateSource(\Twig_Template $template)
{
// Twig templates are not always stored in files, and so there is no
// API to get the filename from a template name in a generic way.
// The logic used here works only for templates stored in app/Resources/views
// and referenced via the "filename.html.twig" notation, not via the "::filename.html.twig"
// one or stored in bundles. This is enough for the needs of the demo app.
$filePath = $this->kernelRootDir . '/Resources/views/' . $template->getTemplateName();
$sourceCode = $template->getSource();
// Temporary workaround for https://github.com/twigphp/Twig/issues/2011
if (null === $sourceCode) {
$sourceCode = @file_get_contents($filePath);
}
return ['file_path' => $filePath, 'starting_line' => 1, 'source_code' => $sourceCode];
}
示例4: getCode
/**
* Gets the code from the template
* @param Twig_Template $template
* @return HTML to display
*/
public function getCode($template)
{
$controllerClass = get_class($this->controller[0]);
if (class_exists('CG\\Core\\ClassUtils')) {
$controllerClass = ClassUtils::getUserClass($controllerClass);
}
$methodName = $this->controller[1];
$controllerLink = $this->githubLocator->getMethodClassLink($controllerClass, $methodName);
$templateLink = $this->githubLocator->getTemplateLink($template->getTemplateName());
$controller = $this->getControllerCode($controllerClass, $methodName);
$template = $this->getTemplateCode($template);
// remove the code block
$template = str_replace('{% set code = code(_self) %}', '', $template);
return <<<EOF
<h4><strong>Controller Code - <a href="{$controllerLink}">Github</a></strong></h4>
<pre class="prettyprint">{$controller}</pre>
<h4><strong>Template Code - <a href="{$templateLink}">Github</a></strong></h4>
<pre class="prettyprint">{$template}</pre>
EOF;
}
示例5: getTemplateName
/**
* Gets the name of the main loaded template.
*
* @return string
*/
public function getTemplateName()
{
return $this->template->getTemplateName();
}
示例6: getTemplateSource
private function getTemplateSource(\Twig_Template $template)
{
return array('file_path' => $this->kernelRootDir . '/Resources/views/' . $template->getTemplateName(), 'starting_line' => 1, 'source_code' => $template->getSource());
}
示例7: callMacro
/**
* Calls macro in a template.
*
* @param Twig_Template $template The template
* @param string $macro The name of macro
* @param array $arguments The arguments of macro
* @param array $namedNames An array of names of arguments as keys
* @param integer $namedCount The count of named arguments
* @param integer $positionalCount The count of positional arguments
*
* @return string The content of a macro
*
* @throws Twig_Error_Runtime if the macro is not defined
* @throws Twig_Error_Runtime if the argument is defined twice
* @throws Twig_Error_Runtime if the argument is unknown
*/
protected function callMacro(Twig_Template $template, $macro, array $arguments, array $namedNames = array(), $namedCount = 0, $positionalCount = -1)
{
if (!isset($template->macros[$macro]['reflection'])) {
if (!isset($template->macros[$macro])) {
throw new Twig_Error_Runtime(sprintf('Macro "%s" is not defined in the template "%s".', $macro, $template->getTemplateName()));
}
$template->macros[$macro]['reflection'] = new ReflectionMethod($template, $template->macros[$macro]['method']);
}
if ($namedCount < 1) {
return $template->macros[$macro]['reflection']->invokeArgs($template, $arguments);
}
$i = 0;
$args = array();
foreach ($template->macros[$macro]['arguments'] as $name => $value) {
if (isset($namedNames[$name])) {
if ($i < $positionalCount) {
throw new Twig_Error_Runtime(sprintf('Argument "%s" is defined twice for macro "%s" defined in the template "%s".', $name, $macro, $template->getTemplateName()));
}
$args[] = $arguments[$name];
if (--$namedCount < 1) {
break;
}
} elseif ($i < $positionalCount) {
$args[] = $arguments[$i];
} else {
$args[] = $value;
}
$i++;
}
if ($namedCount > 0) {
$parameters = array_keys(array_diff_key($namedNames, $template->macros[$macro]['arguments']));
throw new Twig_Error_Runtime(sprintf('Unknown argument%s "%s" for macro "%s" defined in the template "%s".', count($parameters) > 1 ? 's' : '', implode('", "', $parameters), $macro, $template->getTemplateName()));
}
return $template->macros[$macro]['reflection']->invokeArgs($template, $args);
}
示例8: output
/**
* @param FieldDescriptionInterface $fieldDescription
* @param \Twig_Template $template
* @param array $parameters
*
* @return string
*/
public function output(FieldDescriptionInterface $fieldDescription, \Twig_Template $template, array $parameters, \Twig_Environment $environment)
{
$content = $template->render($parameters);
if ($environment->isDebug()) {
$commentTemplate = <<<EOT
<!-- START
fieldName: %s
template: %s
compiled template: %s
-->
%s
<!-- END - fieldName: %s -->
EOT;
return sprintf($commentTemplate, $fieldDescription->getFieldName(), $fieldDescription->getTemplate(), $template->getTemplateName(), $content, $fieldDescription->getFieldName());
}
return $content;
}
示例9: output
/**
* @param FieldDescriptionInterface $fieldDescription
* @param \Twig_Template $template
* @param array $parameters
*
* @return string
*/
public function output(FieldDescriptionInterface $fieldDescription, \Twig_Template $template, array $parameters = array())
{
$content = $template->render($parameters);
if ($this->environment->isDebug()) {
return sprintf("\n<!-- START \n fieldName: %s\n template: %s\n compiled template: %s\n -->\n%s\n<!-- END - fieldName: %s -->", $fieldDescription->getFieldName(), $fieldDescription->getTemplate(), $template->getTemplateName(), $content, $fieldDescription->getFieldName());
}
return $content;
}
示例10: enrichMetdata
protected function enrichMetdata(\Twig_Template $template)
{
$this->context['metadata']['uri'] = $template->getTemplateName();
$this->context['metadata']['lastmod'] = new \DateTime(sprintf('@%d', filemtime($this->app['twig']->getCacheFilename($template->getTemplateName()))));
}
示例11: getUiPageSelf
/**
* @param \Twig_Template $scope
* @param string $name
*
* @return mixed
*/
public function getUiPageSelf(\Twig_Template $scope, $name)
{
$file = $scope->getTemplateName();
$pattern = '/ui\\:(.*):(.*)\\.html\\.twig/';
return preg_replace($pattern, sprintf('ui:$1:%s.html.twig', $name), $file);
}