Im trying to pass my own variable from module to template file .tpl
I have this code that is used for displaying availability in eshop. Product.tpl
{if $product.availability == 'available'}
{if $product.quantity <= 0 && $product.allow_oosp}
{if isset($product.available_date) && $product.available_date != '0000-00-00'}
<i class="fa fa-truck rtl-no-flip" aria-hidden="true"></i>
{$product.availability_message}
({if $product.available_date|strtotime > $smarty.now}<span class="available-date">{l s='naskladnění' d='Shop.Theme.Catalog'} {$product.available_date|date_format:"%d.%m.%Y"}</span>{/if})
{/if}
{/if}{/if}
Then Im having my own module where im assigning value to smarty
Mymodule.php
$in_stock = 1;
$this->context->smarty->assign("is_in_stock", $in_stock);
My question is if there is any way to access my smarty variable directly from theme tpl? I need to set up another {if else} with that variable but cant access it.
When I add variable to custom hook I cant access it neither.. Or maybe I dont know how. I tried to create front controller but nothing happened.
Something like
{if isset($product.available_date) && $mymodule.is_in_stock = 1 && $product.available_date != '0000-00-00'}
You can access functions of your module anywhere in .tpl files by
{YourModule::yourFunction()}
and set if like
{if YourModule::yourFunction() != 1}
Hello
{/if}
I use this code in Prestashop
{if (strpos($product.name, 'TVNUMBER1') !== false)}
THIS PRODUCT IS IN SALE
{/if}
So whenever I want to display that certain products are in sale, I have to go line by line, specifying the same product i.e."TVNUMBER1". I want to be able to write an array detailing all the products I have in sale "TV1, TV2, TV3", and get a code like this:
{if (strpos($product.name, '$array') !== false)}
THIS PRODUCT IS IN SALE
{/if}
I've tried similar examples found here, but I can't get them to work, either in Prestashop or in PHP testers online. It looks super simple, but I can't get around it.
I think what you want is the in_array php function, that check if a given $needle is or not in an array.
So what you should do is :
{if (in_array($product.name, '$array') !== false)}
THIS PRODUCT IS IN SALE
{/if}
Then in your controller you can assign the array to smarty :
$arr = array('TVNUMBER1', 'TVNUMBER2', 'TVNUMBER3');
$smarty->assign('myArray', $arr);
It seems you are using Smarty as template engine. So you could do something like this (from the doc).
In the controller
//Give it to the view
$arr = array('TVNUMBER1', 'TVNUMBER2');
$smarty->assign('myArray', $arr);
And in the view
//In the view, loop over the array
{foreach from=$myArray item=productName}
//If your product is among the in-sale ones, show the message
{if (strpos($product.name, productName) !== false)}
THIS PRODUCT IS IN SALE
{/if}
{/foreach}
how can I add/print tracking number on invoice?..
I used the code below
{l s='Tracking Number:' pdf='true'}
{$order->shipping_number}
returns blank, but on view order it has a tracking number. (image below)
orders->shipping_number field is blank.
Thanks.
adding on invoice.tpl
{foreach from=$order->getShipping() item=line}
{if $line.url != '' || $line.tracking_number != ''}
{'Tracking Number : '}
{$line.tracking_number}
{/if}
{/foreach}
solves the issue.
I have global function defined in php:
function tabIsProtected($tabNr)
{
...
return true;
}
Now this works in Smarty:
{if tabIsProtected($tabnr)}
{assign var="tabProtected" value=true}
{else}
{assign var="tabProtected" value=false}
{/if}
And this is not:
{assign var="tabProtected" value=tabIsProtected($tabnr)}
When I print $tabProtected variable I get string "tabIsProtected(9)" (for $tabnr = 9) and function tabIsProtected isn't even called!
Is there any way to assign function return value directly in template using Smarty 2?
IMPORTANT: I don't want $smarty->assign(...) in php or Smarty3 solutions. Just one liner directly in template.
I'd like to replace left_column with center_column just on mobile. It works well on tablet and laptop.
As you can see in attachment I have tried to replace left_column -which is marked with red rectangle- with center_column -which is marked with blue rectangle- just on mobile device.
http://i.imgur.com/9z8XHvI.png
{if isset($left_column_size) && !empty($left_column_size)}
{$HOOK_LEFT_COLUMN}
{/if}
{if isset($left_column_size) && isset($right_column_size)}{assign var='cols' value=(12 - $left_column_size - $right_column_size)}{else}{assign var='cols' value=12}{/if}
{/if}