|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
kevlarbox Smarty n00b
Joined: 05 Oct 2010 Posts: 3
|
Posted: Tue Oct 05, 2010 3:26 pm Post subject: Comment déclarer ma function sur un Tpl prestashop ? |
|
|
Bonjour à tous,
je suis pas trop novice en php , mais beaucoup plus en Smarty et je cherche à déclarer une function dans le template.
Ma function est la suivante :
Code: | function chatel($invoice_date, $day)
{
if ($invoice_date > 0)
{
$date = date_create($invoice_date);
date_modify($date, '+'.$day.' day'); // Ajout des jours.
$frdate= date_format($date, 'd-m-Y');
$joursem = array("Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi");
// extraction des jour, mois, an de la date
list($jour, $mois, $annee) = explode('-', $frdate);
// calcul du timestamp
$timestamp = mktime (0, 0, 0, $mois, $jour, $annee);
// affichage du jour de la semaine
$jour = $joursem[date("w",$timestamp)];
if ($jour == 'Samedi') $date->modify('+2 day');
if ($jour == 'Dimanche') $date->modify('+1 day');
echo date_format($date, 'd-m-Y');
}
} |
et je l'a récupère avec ceci en php :
Code: | foreach( $orders as &$order ) {
chatel($order['invoice_date'],'28');
} |
Ca fonctionne bien, mais je voudrais l'interpréter en tpl smarty comme ceci :
Code: | {foreach from=$orders item=order name=myLoop}
...ici ?
{/foreach} |
Je pense que mon " echo " devrais être réinterpréter différemment, comment faire ? j'ai essayé différente solution sans succès ..
Merci d'avance pour une éventuelle réflexion. |
|
Back to top |
|
kevlarbox Smarty n00b
Joined: 05 Oct 2010 Posts: 3
|
Posted: Tue Oct 05, 2010 11:28 pm Post subject: |
|
|
J'ai observé ce qui se fait un peu partout mais le résultat n'est pas encore ça ..
mon code modifié qui plante :
Code: |
function chatel($params)
{ global $smarty;
$invoice_date = $params['invoice_date'];
$day = $params['day'];
if ($invoice_date > 0)
{
$date = date_create($invoice_date);
date_modify($date, '+'.$day.' day'); // Ajout des jours.
$frdate= date_format($date, 'd-m-Y');
$joursem = array("Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi");
// extraction des jour, mois, an de la date
list($jour, $mois, $annee) = explode('-', $frdate);
// calcul du timestamp
$timestamp = mktime (0, 0, 0, $mois, $jour, $annee);
// affichage du jour de la semaine
$jour = $joursem[date("w",$timestamp)];
if ($jour == 'Samedi') $date->modify('+2 day');
if ($jour == 'Dimanche') $date->modify('+1 day');
echo date_format($date, 'd-m-Y');
}
}
tpl smarty :
{foreach from=$orders item=order name=myLoop}
{chatel invoice_date=$order.invoice_date day=28}
{/foreach}
|
Je cherche encore |
|
Back to top |
|
Gowser Smarty Pro
Joined: 19 Feb 2008 Posts: 104 Location: Nantes (France)
|
Posted: Wed Oct 06, 2010 10:39 am Post subject: |
|
|
Bonjour le mieux serait de faire un plugin pour ta fonction, ca serait plus simple a gerer
http://www.smarty.net/manual/fr/plugins.php
(penser à modifier vos titres de post en résolu !)
Last edited by Gowser on Mon Nov 15, 2010 2:35 pm; edited 1 time in total |
|
Back to top |
|
kevlarbox Smarty n00b
Joined: 05 Oct 2010 Posts: 3
|
Posted: Wed Oct 06, 2010 3:41 pm Post subject: |
|
|
Merci Gowser pour cette piste , finalement j'ai repris la librairie propre à Presta pour déclarer (dans init.php) ma function correctement dans le template et tout fonctionne !
En tout cas j'ai bien appris en suivant tes réponses sur des cas similaires postés sur ce site.
Bonne continuation à vous.
Kévin |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|