Outils pour utilisateurs

Outils du site


webdev:prestashop:smarty

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Prochaine révision
Révision précédente
webdev:prestashop:smarty [22/02/2017 15:04] – créée dolowebdev:prestashop:smarty [21/07/2017 11:04] (Version actuelle) dolo
Ligne 1: Ligne 1:
 +====== 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 ====
 +
 +<Code linenums><pre>{$countries|@print_r}</pre></Code>
 +> 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 :**
 +
 +<Code linenums>
 + {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<br/>
 + <span class="date">
 + {$projet_date.day} {$months.{$projet_date.month}}<br/>
 + {$projet_date.year}
 + </span>
 +</Code>
 +
 +**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__
 +<Code linenums>
 +Media::addJsDef(array('var_name' => $variable));
 +Media::addJsDef( array('time_remaining' => $time_remaining) );
 +</Code>
 +
 +__Smarty__ : voir lien 1
 +<Code>
 +{addJsDef wishlistProductsIds=$wishlist_products}
 +{addJsDef mySliderCount=7}
 +</Code>
 +
 +==== Récupérer des globales PHP ====
 +[[http://www.smarty.net/docs/en/language.variables.smarty.tpl|Check dat]]
 +
 +=== Restriction par IP ===
 +<Code linenums>
 +{if $smarty.server.REMOTE_ADDR == '82.245.97.150'}
 + {debug}
 +{/if}
 +</Code>