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
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}
In smarty the comparison operators are like in many languages >= and <=. => has a different meaning in PHP, and smarty is translated into PHP before execution.
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 : <=
Related
I'm trying to assign a var to be used in an if statement it looks like this:
{assign var="worldwide" value=false}
{assign var="idCategory" value=15}
{foreach from=$cart.products item=product}
{if $product.id_category_default == $idCategory}
{assign var="worldwide" value=true}
{/if}
{/foreach}
{if $worldwide == true}
{/if}
In its current state it however is true if just one product of category value 15 is in cart. I want it so that it is only true if all products in cart are part of same category. I'm using Prestashop 1.7
Use the cycle in reverse and abort when one of the elements is not what you want, like this:
{assign var="worldwide" value=true}
{assign var="idCategory" value=15}
{foreach from=$cart.products item=product}
{if $product.id_category_default != $idCategory}
{assign var="worldwide" value=false}
{break}
{/if}
{/foreach}
{if $worldwide == true}
{/if}
I use Prestashop and I need to add a specific slideshow for the category->id 1 on the top of the category's products, and it's need to be within the code below:
I tried to insert this code:
{if category->id == '1'}
...
{/if}
Within this code:
{if isset($category)}
{if $category->id AND $category->active}
{if $scenes || $category->description || $category->id_image}
...
{if $scenes}
...
{include file="$tpl_dir./scenes.tpl" scenes=$scenes}
{if $category->description}
...
{if Tools::strlen($category->description) > 350}
...
{else}
{$category->description}
{/if}
...
{/if}
...
{else}
THERE'S WHERE I TRIED INSERT THE CODE
{/if}
{/if}
{/if}
{/if}
And it doesn't work.. why?
Regards,
Because you have placed in wrong position :)
{if isset($category)}
{if $category->id AND $category->active}
{if $scenes || $category->description || $category->id_image}
...
{if $scenes}
...
{include file="$tpl_dir./scenes.tpl" scenes=$scenes}
{if $category->description}
...
{if Tools::strlen($category->description) > 350}
...
{else}
{$category->description}
{/if}
...
{/if}
...
{else}
THERE'S WHERE I TRIED INSERT THE CODE (WRONG)
{/if}
{/if}
THERE'S WHERE YOU HAVE TO PLACE THE CODE
{if $category->id eq 1}
/* some stuff */
{/if}
{/if}
{/if}
For the next time fix the indentation and you reach the goal by yourself ;)
Insert it before the last
{else}
i am trying to check if a field in my prestashop db is empty. In case is empty i want to display a default message otherwise i want to display whatever field contains. In my product.tpl file i have use these 4 versions but nothing works:
{if !$product->available_now}
{l s = 'Default Message'}
{else}
{$product->available_now}
{/if}
---
{if empty($product->available_now)}
{l s = 'Default Message'}
{else}
{$product->available_now}
{/if}
---
{if $product->available_now === NULL}
{l s = 'Default Message'}
{else}
{$product->available_now}
{/if}
---
{if $product->available_now == ""}
{l s = 'Default Message'}
{else}
{$product->available_now}
{/if}
whats the correct way?
Thanks
{if ! isset($product->available_now)}
Its not Set
{/if}
Try it
Need to delete first element after all this statements, i try to add key=i to second foreach, and add {if $i!=0}, but it dont work for me, because i have multilevel system and after all if statements first $i is different for all pages.
{foreach from=$page.path item=e}
{assign var=element value=0}
{foreach from=$menu3 item=r}
{if $e.page_id==$r.page_id}{assign var=element value=$r}{/if}
{if $element._left < $r._left && $element._right > $r._right}
{if $r._level==$element._level+1 && $r._level==$page._level}
{$r.name}
{/if}
{/if}
{/foreach}
{/foreach}
P.S. Sorry for my English.
Add a name to you foreach and do something like this to get index
{foreach from=$items key=myId item=i name=foo}
{$smarty.foreach.foo.index} <!-- It will show index -->
{/foreach}
I assume you don't want to display first element in each of the menus you have, right?
{foreach from=$page.path item=e}
{assign var=first_skipped value=0}
{assign var=element value=0}
{foreach from=$menu3 item=r}
{if !$first_skipped}
{assign var=first_skipped value=1}
{else}
{if $e.page_id==$r.page_id}{assign var=element value=$r}{/if}
{if $element._left < $r._left && $element._right > $r._right}
{if $r._level==$element._level+1 && $r._level==$page._level}
{$r.name}
{/if}
{/if}
{/if}
{/foreach}
{/foreach}
I have written my code like this,
{if $quant eq 1}
{if $val neq ""}
.....//some code
{else}
.....//some code
{/if}
{else if $quant eq 0}
.....//some code
{/if}
but the above nested smarty if condition is not working as expected and it always give the results in else condition.Can anyone help me please, Don't know where am making mistake...
In smarty you have to write if else condition like that:
{if $quant eq 1}
{elseif $val neq ""}
.....//some code
{elseif $val neq "3"}
.....//some code
{elseif $quant eq 0}
.....//some code
{/if}
OR
{if $quant eq 1}
{if $val neq ""}
.....//some code
{else}
.....//some code
{/if}
{else}
{if $quant eq 0}
.....//some code
{/if}
.....//some code
{/if}
I hope this would help you.