简体   繁体   中英

Symfony If Statements

I am hoping to get some assistance with Symfony 'if' statements.

Essentially I am trying to do, if the price value is equal to or greater than $500, display 'Free Shipping', if otherwise, display 'Click & Collect'.

This is a for a prestashop theme and I have the below coding after the initial if statement

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

The whole coding of this part is:

{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}

Any help would be greatly appreciated.

Thanks, Cohen

If it is supposed to be a template using twig if statements must be written as follow:

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

You can use both :

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

to make different cases.

You can set variables like this:

{% set var='toto' %}

and display a variable like this:

{{ var }}

And finally comparison operators are written as they are pronounced:

  • greater than or equal : >=
  • less than or equal : <=

It's hard to tell from your posting what you're trying to achieve. i suspect the changes you want might be something like this:

{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}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM