Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么细枝延伸标记有时不';你看不到一些变量吗?_Php_Symfony_Twig - Fatal编程技术网

Php 为什么细枝延伸标记有时不';你看不到一些变量吗?

Php 为什么细枝延伸标记有时不';你看不到一些变量吗?,php,symfony,twig,Php,Symfony,Twig,在Symfony2中,我创建了简单的操作: public function testAction() { return $this->render('TestBundle::test.html.twig', array( 'testBool' => true, 'testTplPath' => 'TestBundle::base.html.twig' )); } base.html.twig: <ht

在Symfony2中,我创建了简单的操作:

public function testAction()
{        
    return $this->render('TestBundle::test.html.twig', array(
        'testBool'    => true,
        'testTplPath' => 'TestBundle::base.html.twig'
    ));
}
base.html.twig:

<html><body>{% block content %}{% endblock %}</body></html>
{%block content%}{%endblock%}
现在我的test.html.twig模板中的extends标记有问题,如果我在这个标记中使用这样的简单字符串:
{%extends'TestBundle::base.html.twig%}
一切正常,但这不起作用:
{%extends testTplPath%}
。第二个示例抛出错误:
变量“testTplPath”不存在于TestBundle::test.html.twig的第1行

这很好:
{%extensedtestbool?'TestBundle::base.html.twig':'blah%}

这会引发异常:
{%extensed testBool?testTplPath:'blah'%}
-
变量“testBool”在TestBundle::test.html.twig的第1行中不存在(请注意,twig这次引发了关于
testBool
变量的异常-为什么?!)

根据TWIG文档,所有的例子都是我们应该做的,我不知道我做错了什么

我做了很多测试,当exted看到变量时和没有看到变量时,我无法找出任何模式

我目前使用的是Twig v1.16.0和Symfony 2.5.4


更新:我注意到另一件奇怪的事情,如果我放入
testTplPath
有效路径或创建任何其他动态表达式,返回我得到的有效路径
变量“[表达式中的第一个变量]”不存在
异常,但如果它返回我得到的无效路径:
找不到模板“TestBundle::SomeInvalidTemplate.html.twig”

我发现了问题


在template test.html.twig中,我也使用了全局表单,我确信这个表单并不重要,但是…看起来这个bug还没有完全修复。我用[\u self,form\u theme]]从{%form\u theme表单中删除了{u self,现在一切都正常了。

你试过用括号括住表达式吗?
(testBool?testTplPath:'blah')
?我现在尝试了它,但没有任何帮助:/如果您使用
{%set base_template=(testBool | default(false)?testTplPath | default('TestBundle::base.html.twig'):'SomeOtherBundle::base.html.twig')%}{%extensed base_template%}
变量“base_template”“不存在
我认为您不能在extends语句中使用字符串变量。请看这里:{%extends some_var%}仅当某个_var是一个Twig_模板对象时才有效。还有其他方法可以完成您尝试的操作。