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
Related
I want the following:
& I understand I have to take the codes from context.php of PrestaShop but I seem to be making an error. A link to getcontext is as follows: (The code to detect mobile device is here)
https://github.com/PrestaShop/PrestaShop/blob/develop/classes/Context.php
{if isset($products) AND $products}
{$tabname=rand()+count($products)}
{if isset($display_mode) && $display_mode == 'carousel'}
{include file="{$items_owl_carousel_tpl}" items=$products image_size=$image_size}
{else}
{if device is MOBILE} /* Correct Code Needed */
{include file="{$items_normal_tpl}" items=$products image_size="homepage_default"}
{else device is NOT MOBILE} /* Correct Code Needed */
{include file="{$items_normal_tpl}" items=$products image_size="home_default"}
{/if}
{/if}
{/if}
What codes should I enter in the IF condition to make sure it detects mobile and not mobile.
Also is the IF condition written properly, what should I change in this code?
This is .TPL File.
try with :
{if Context::getContext()->isMobile() == 1}
{if Context::getContext()->getDevice() != 2}
// TABLETTE
{else}
// MOBILE
{/if}
{else}
// PC
{/if}
Regards
In Prestashop 1.7.8.2 it works this -->
{assign var="dispositivo" value="desktop"}
{if Context::getContext()->isMobile()}
{assign var="dispositivo" value="mobile"}
{else if Context::getContext()->isTablet()}
{assign var="dispositivo" value="tablet"}
{else}
{assign var="dispositivo" value="desktop"}
{/if}
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 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 : <=
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 have smarty value if it empty need another result
{get_video_meta video_id=$video_data.id key='test'}
This value print "test" If this value is empty else how can I use?
{if !empty({get_video_meta video_id=$video_data.id key='test'})}
No value
{else}
{get_video_meta video_id=$video_data.id key='test'}
{/if}
This code not work
You could use the {capture} function to capture the output into a variable, then choose what to do with it:
{capture name="video_meta"}{get_video_meta video_id=$video_data.id key='test'}{/capture}
{if empty($smarty.capture.video_meta)}
No value
{else}
{$smarty.capture.video_meta}
{/if}
You can assign value to variable:
{if empty($code)}
{assign var='code' value='404'}
{/if}
but i suppose that you need something like:
{if empty($video_data.id)}
No value
{else}
{get_video_meta video_id=$video_data.id key='test'}
{/if}
because get_video_meta - it's smarty plugin, and you can't use it like you try to use...
In foreach:
{foreach from=$video_data key=k item=v}
{if empty($k)}
No value
{else}
{get_video_meta video_id=$v.id key=$k}
{/if}
{/foreach}