2015-12-15 111 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