Search code examples
phpsmarty

Condition if zero or less - working with if 0 but unsure or is less


I have the following code :

{if $product.amount == 0}
      <div class="ofs-label">{$lang.price}:</div>
{/if}

which at the moment shows the HTML if the amount is equal to 0, however, how can I modify this so it shows the HTML if it is equal to 0 or less?


Solution

  • You might want to look at comparison operators in PHP. Here's a great resource from php.net

    For your purpose, you would want to do this:

    {if $product.amount <= 0}
    <div class="ofs-label">{$lang.price}:</div>
    {/if}
    

    As you can see, the <= operator will return TRUE if $product.amount is less than or equal to zero.