2017-02-06 32 views
0

我希望能得到一些Symfony'if'語句的幫助。Symfony If語句

基本上我試圖做的,如果價格值等於或大於500美元,顯示'免費送貨',否則,顯示'點擊&收集'。

這是一個的Prestashop主題,我有以下編碼初始後if語句

{else} 
         {if $pricediplay ==> 500} {l s='Free Shipping!'}{/if} 
        {else} 
         {if $pricediplay ==< 499.99} {l s='Click & Collect'}{/if} 
        {/if} 

這一部分的整個編碼是:

{if $option.total_price_with_tax && !$option.is_free && 
(!isset($free_shipping) || (isset($free_shipping) && !$free_shipping))} 
    {if $use_taxes == 1} 
     {if $priceDisplay == 1} 
       {convertPrice price=$option.total_price_without_tax} 
       {if $display_tax_label} 
        {l s='(tax excl.)'} 
       {/if} 
      {else} 
       {convertPrice price=$option.total_price_with_tax} 
       {if $display_tax_label} 
        {l s='(tax incl.)'} 
       {/if} 
     {/if} 
      {else} 
       {convertPrice price=$option.total_price_without_tax} 
    {/if} 
{else} 
    {if $pricediplay ==> 500} 
     {l s='Free Shipping!'} 
    {/if} 
{else} 
    {if $pricediplay ==< 499.99} 
     {l s='Click & Collect'} 
    {/if} 
{/if} 

任何幫助將不勝感激。

感謝, 科恩

+0

目前會發生什麼?看起來你可能在'{if $ pricediplay => 500}之後打斷了你的大括號' – Andy

+0

當我應用這些更改時,它會產生500內部服務器錯誤。我確信我做錯了什麼,只是不確定它是什麼。 – geekcohen

+0

破碎的牙套可能會導致這種情況。看看你的錯誤日誌,看看錯誤信息是什麼 – Andy

回答

0

很難從你的帖子告訴你想達到的目標。我懷疑你想可能是這樣的變化:

{if $option.total_price_with_tax && !$option.is_free && 
(!isset($free_shipping) || (isset($free_shipping) && !$free_shipping))} 
    {if $use_taxes == 1} 
     {if $priceDisplay == 1} 
      {convertPrice price=$option.total_price_without_tax} 
      {if $display_tax_label} 
       {l s='(tax excl.)'} 
      {/if} 
     {else} 
      {convertPrice price=$option.total_price_with_tax} 
      {if $display_tax_label} 
       {l s='(tax incl.)'} 
      {/if} 
     {else} 
      {convertPrice price=$option.total_price_without_tax} 
     {/if} 
    {/if} 
{else} 
    {if $priceDisplay => 500} 
     {l s='Free Shipping!'} 
    {/if} 
{else} 
    {if $priceDisplay =< 499.99} 
     {l s='Click & Collect'} 
    {/if} 
{/if} 
+0

如果pricingisplay大於或等於500美元,那麼它顯示「免運費」,我希望實現該目標。 如果它小於或等於499.99美元,它顯示'點擊並收集' 我已經按照您的編碼示例完成,但沒有運氣。我認爲這是大於'==>'的配置,它會產生500個內部服務器錯誤。 – geekcohen

+0

如果'500'是它出現的地方,可以改爲:'500.00'我的意思是加2個小數位。 –

+0

仍然沒有快樂。我需要嘗試獲取大於或等於配置的正確值。 – geekcohen

1

如果它應該是用樹枝模板if語句必須寫成如下:

{% if ... %} 
    //your own logic... 
{% endif %} 

您可以同時使用:

{% elseif ... %} 
{% else %} 

作出不同的情況。

您可以設置變量是這樣的:

{% set var='toto' %} 

,並顯示像這樣的變量:

{{ var }} 

最後,因爲它們是明顯的比較操作符記:

  • 更大大於或等於:> =
  • 小於或等於電話:< =
+0

謝謝Olivier,是否正確? '{%VAR集= 「500」 %} {%如果$ priceDisplay == 1%} \t {%如果$ priceDisplay> = {{VAR}}%} '免費送貨!' {%ENDIF%} \t \t {%ELSEIF%} '點擊和收集' \t {%其他%} {%ENDIF%}' – geekcohen

+0

{%如果$ priceDisplay> = VAR%}「免費送貨! {%else%}'點擊並收集'{%endif%}。在你的例子中,var將是一個字符串,而不是一個整數,那你想要什麼?如果沒有,那麼你必須寫{%set var = 500%}(不含引號) – OlivierC