View previous topic :: View next topic |
Author |
Message |
toams69 Smarty Rookie
Joined: 11 Dec 2010 Posts: 7
|
Posted: Sat Dec 11, 2010 4:01 pm Post subject: smarty_modifier |
|
|
Bonjour, j ai essayé il y a quelques jours de créer ma propre fonction
dans le repertoire plugin.
Celle ci se nomme smarty_modifier_inputElem($idInput, $nameInput, $typeInput, $valueInput, $default) et retourne bien le résultat de son exécution.
J ai testé cette fonction avant de la mettre en plugin.
Je suis maintenant bloquer pour l appel dans le Template.
J ai essayer ceci
{"id" ; "name" ; "select" ; "val" ; "0" | inputElem}
{"id" , "name" , "select" , "val" , "0" | inputElem}
{"id" | "name" | "select" | "val" | "0" | inputElem}
mais cela n a pas fonctionné.
Je débute en smarty du coup, je suis un peu perdu...
Merci de votre aide |
|
Back to top |
|
Gowser Smarty Pro
Joined: 19 Feb 2008 Posts: 104 Location: Nantes (France)
|
Posted: Sat Dec 11, 2010 8:28 pm Post subject: |
|
|
Bonjour / bonsoir,
Pourrais-tu poster ton code et indiquer ta version de smarty ?
++ |
|
Back to top |
|
toams69 Smarty Rookie
Joined: 11 Dec 2010 Posts: 7
|
Posted: Sat Dec 11, 2010 11:15 pm Post subject: |
|
|
Code: | function smarty_modifier_inputElem($idInput, $nameInput, $typeInput, $valueInput, $default)
{
$ret = "";
switch ($typeInput)
{
case ("select"):
$tabValue = explode(";", $valueInput);
$ret .= "$nameInput <select class=\"inputSel\" name=\"input-$idInput\">";
foreach ($tabValue as $value)
{
$tabValue2 = explode("|", $value);
if ($default == $tabValue2[0])
$ret .= "<option value=".$tabValue2[0]." selected>".$tabValue2[1]."</option>";
else
$ret .= "<option value=".$tabValue2[0]." >".$tabValue2[1]."</option>";
}
$ret .= "</select>";
break;
case ("integer"):
$ret .= "$nameInput <input class=\"inputInt\" type=\"text\" value=\"$default\" name=\"input-$idInput\" />";
break;
case ("text"):
$ret .= "$nameInput <input class=\"inputTxt\" type=\"text\" value=\"$default\" name=\"input-$idInput\" />";
break;
}
return $ret;
}
|
et j utilise smarty 2.6.26 |
|
Back to top |
|
Gowser Smarty Pro
Joined: 19 Feb 2008 Posts: 104 Location: Nantes (France)
|
Posted: Sun Dec 12, 2010 1:07 am Post subject: |
|
|
A je vois, c'est plutot une fonction de template qu'il faudrait que tu fasses car la tu fait un "modifier" qui, comme son nom l'indique , modifie une variable.
Voici ce qu'il faudrait que tu fasses :
Le fichier s'appellerait désormais 'function.inputelem.php' (en minuscule car c'est la nouvelle norme smarty 3 donc au cas, prefere les minuscule en cas de montée de version de smarty)
Code: |
function smarty_modifier_inputElem($params, &$smarty)
{
$idInput = $params['idInput'];
$nameInput = $params['nameInput'];
$typeInput = $params['typeInput'];
$valueInput = $params['valueInput'];
$default = $params['default'];
$ret = "";
switch ($typeInput)
{
case ("select"):
$tabValue = explode(";", $valueInput);
$ret .= "$nameInput <select class=\"inputSel\" name=\"input-$idInput\">";
foreach ($tabValue as $value)
{
$tabValue2 = explode("|", $value);
if ($default == $tabValue2[0])
$ret .= "<option value=".$tabValue2[0]." selected>".$tabValue2[1]."</option>";
else
$ret .= "<option value=".$tabValue2[0]." >".$tabValue2[1]."</option>";
}
$ret .= "</select>";
break;
case ("integer"):
$ret .= "$nameInput <input class=\"inputInt\" type=\"text\" value=\"$default\" name=\"input-$idInput\" />";
break;
case ("text"):
$ret .= "$nameInput <input class=\"inputTxt\" type=\"text\" value=\"$default\" name=\"input-$idInput\" />";
break;
}
return $ret;
}
|
Et tu l'apellerais dans ton template comme cela :
Code: |
{inputelem idInput="un_id" nameInput="un_nom" typeInput="un_type" valueInput="une_valeur" default="une_valeur_par_defaut"}
|
Pour t'aider :
Les fonctions de templates : http://www.smarty.net/docsv2/fr/plugins.functions.tpl
Les modifiers : http://www.smarty.net/docsv2/fr/plugins.modifiers.tpl
Voila
++ _________________ N'oubliez pas de mettre le tag "[Résolu]" sur vos post |
|
Back to top |
|
toams69 Smarty Rookie
Joined: 11 Dec 2010 Posts: 7
|
Posted: Sun Dec 12, 2010 5:22 pm Post subject: |
|
|
Ok, je vais tester cela, je te remercie déjà |
|
Back to top |
|
toams69 Smarty Rookie
Joined: 11 Dec 2010 Posts: 7
|
Posted: Sun Dec 12, 2010 5:28 pm Post subject: |
|
|
J'ai du coup essayé comme tu me l avais conseillé mais j ai ces warnings:
Warning: Missing argument 3 for smarty_function_inputelem(), called in C:\Wamp\www\Acteasy Local\ActeasyEclipse\outilsWeb\templates_c\%%F2^F20^F209AEA7%%addelemf.tpl.php on line 67 and defined in C:\Wamp\www\Acteasy Local\ActeasyEclipse\outilsWeb\libs\plugins\function.inputelem.php on line 2
Warning: Missing argument 4 for smarty_function_inputelem(), called in C:\Wamp\www\Acteasy Local\ActeasyEclipse\outilsWeb\templates_c\%%F2^F20^F209AEA7%%addelemf.tpl.php on line 67 and defined in C:\Wamp\www\Acteasy Local\ActeasyEclipse\outilsWeb\libs\plugins\function.inputelem.php on line 2
Warning: Missing argument 5 for smarty_function_inputelem(), called in C:\Wamp\www\Acteasy Local\ActeasyEclipse\outilsWeb\templates_c\%%F2^F20^F209AEA7%%addelemf.tpl.php on line 67 and defined in C:\Wamp\www\Acteasy Local\ActeasyEclipse\outilsWeb\libs\plugins\function.inputelem.php on line 2
pourtant j ai bien copier la ligne que tu avais ecrit avec les mm nom de variables etc.. |
|
Back to top |
|
toams69 Smarty Rookie
Joined: 11 Dec 2010 Posts: 7
|
Posted: Sun Dec 12, 2010 6:02 pm Post subject: |
|
|
C'est bon j ai trouve, il faut ecrire la fonction comme ceci pour que cela fonctionne
Code: | function smarty_function_inputelem ($params, &$smarty)
{
// je récupère la variable even_date grâce à son nom
$idInput = $params['idInput '];
$nameInput = $params['nameInput '];
$typeInput = $params['typeInput '];
$valueInput = $params['valueInput '];
$default = $params['default '];
}
|
par contre je voulai appele la fonction comme ceci dans le template,
Code: | {section name=idx2 loop=$smarty_FurnTab}
{if $smarty_FurnTab[idx2].ID_INPUT_GROUP == $smarty_GroupInput[idx].ID_INPUT_GROUP}
{inputelem idInput="$smarty_FurnTab[idx2].ID_INPUT"
nameInput="$smarty_FurnTab[idx2].NAME_INPUT"
typeInput="$smarty_FurnTab[idx2].TYPE_INPUT"
valueInput="$smarty_FurnTab[idx2].VALUES_INPUT"
default="$smarty_FurnTab[idx2].DEFAULT_VALUE"}
{/if}
{/section} |
mais cela marche pas, as tu une idée ? |
|
Back to top |
|
toams69 Smarty Rookie
Joined: 11 Dec 2010 Posts: 7
|
Posted: Sun Dec 12, 2010 6:06 pm Post subject: |
|
|
Il suffit d'enlever les "
du coup merci beaucoup pour ton aide |
|
Back to top |
|
|