简体   繁体   English

Symfony If陈述

[英]Symfony If Statements

I am hoping to get some assistance with Symfony 'if' statements. 我希望在Symfony的“ if”语句中获得一些帮助。

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'. 本质上,我正在尝试这样做,如果价格值等于或大于$ 500,则显示“免费送货”,否则,显示“点击并收集”。

This is a for a prestashop theme and I have the below coding after the initial if statement 这是一个prestashop主题,在初始if语句后有以下代码

{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: 如果应该使用twig作为模板,则必须将语句编写如下:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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