Outils pour utilisateurs

Outils du site


Panneau latéral

webdev:prestashop:smarty

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})

<pre>{$countries|@print_r}</pre>
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<br/>
	<span class="date">
		{$projet_date.day} {$months.{$projet_date.month}}<br/>
		{$projet_date.year}
	</span>

Intégrer javascript

Penser à mettre le code entre des balises {literal} pour éviter des erreurs avec les { }

Doc

Créer une variable

1 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

Restriction par IP

{if $smarty.server.REMOTE_ADDR == '82.245.97.150'}
	{debug}
{/if}
webdev/prestashop/smarty.txt · Dernière modification: 21/07/2017 11:04 de dolo