mercredi 29 octobre 2008

smarty plugin while

Dans le repertoire smarty/plugins créer le fichier compiler.while.php et placer dedans le code suivant:

$this->register_compiler_function('/while', 'smarty_compiler_endwhile');

function smarty_compiler_while($tag_arg, &$smarty) {
$res = $smarty->_compile_if_tag($tag_arg);
preg_match("/<\?php if (.*): \?>/",$res,$token);
return "while " . $token[1] . " {";
}

function smarty_compiler_endwhile($tag_arg, &$smarty) {
return "}";
}

vous pouvez l'utiliser dans vos templates comme suivant:

{assign var="test" value=1}
{while ($test <= 5)}
{assign var="test" value="`$test+1`"}
passage numero {$test}
{/while}

Aucun commentaire: