2015-12-15 195 views
0

我想设置href的值取决于引用者的值,但它不起作用。我是否写得很好?根路径树枝限制

{% if "{{app.request.headers.get('referer')}}" == "{{path('userPurchaseBidGetAll', {companyId: app.user.company.id})}}" %} href="{{path('userPurchaseBidGetAll', {companyId: app.user.company.id})}}"{% endif %} 

回答

3

的代码已经在一根树枝逻辑标签,所以引号“”里面的{{ }}标签将被解释为一个字符串。你可以只写有逻辑:

{% if app.request.headers.get('referer') == path('userPurchaseBidGetAll', {companyId: app.user.company.id})%} href="{{path('userPurchaseBidGetAll', {companyId: app.user.company.id})}}"{% endif %} 

您可以访问树枝变量树枝逻辑标签内(如app);

+0

当我把三个等于我得到一个异常:值“=”的意外令牌“运算符” – dimvcl

+0

对不起,我混淆了PHP语法与树枝一,我会纠正这一点。谢谢! – anegrea

+0

我仍然没有得到任何我打印这两个变量,我得到相同的结果,但如果不能正常工作。 – dimvcl