====== Smarty ======
==== Conditions ====
$this->context->smarty->assign('canUpload', false);
{if $canUpload == true}
...
{else}
...
{/if}
http://www.smarty.net/docsv2/en/language.function.if.tpl
On peut utiliser les **(int) $variable** (ou **{$variable|intval}**)
==== Print_r une variable ====
{$countries|@print_r}
> The @ tells smarty to pass the entire array to the modifier rather than calling the modifier for each element of the array. Smarty also ships with a modifier that does similar to print_r(): {$foo|@debug_print_var}. You may also consider smarty's debug facility (which you can enable in-template by inserting a {debug} tag or you can enable by configuring the Smarty object appropriately -- see the docs for more info)
**Debug mode**\\
Ajouter dans un template :
{debug}
**Choper l'index d'un foreach**
{foreach $products as $product}
$product@index
Put that index into an array : **$carriers.{$option@index}.id_carrier}**
**Appel d'une fonction php :**
{Customer::hadCustomerInvested({$cart->id_customer}, {$product.id_product})}
{assign var='projet_date' value=date_parse($product.date_debut)}
{assign var='months' value=['','janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre']}
Ouverture le
{$projet_date.day} {$months.{$projet_date.month}}
{$projet_date.year}
**Intégrer javascript**
Penser à mettre le code entre des balises {literal} pour éviter des erreurs avec les { }
[[http://www.smarty.net/docsv2/en/language.function.literal.tpl|Doc]]
==== Créer une variable ====
[[http://nemops.com/prestashop-functions-5/#.VjSHDLfnvmg|1]] [[http://stackoverflow.com/questions/36650203/prestashop-access-php-variable-in-a-js-file-which-is-hooked-in-header|2]]
__PHP__
Media::addJsDef(array('var_name' => $variable));
Media::addJsDef( array('time_remaining' => $time_remaining) );
__Smarty__ : voir lien 1
{addJsDef wishlistProductsIds=$wishlist_products}
{addJsDef mySliderCount=7}
==== Récupérer des globales PHP ====
[[http://www.smarty.net/docs/en/language.variables.smarty.tpl|Check dat]]
=== Restriction par IP ===
{if $smarty.server.REMOTE_ADDR == '82.245.97.150'}
{debug}
{/if}