|
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 |
ben Smarty Rookie
Joined: 21 Sep 2004 Posts: 5
|
Posted: Wed Sep 22, 2004 7:09 pm Post subject: Splice function... |
|
|
to optimize the speed of my template I'd like to do something like the splice function in PHP on a table of my template, in each loop of a {section}... is it possible? |
|
Back to top |
|
ben Smarty Rookie
Joined: 21 Sep 2004 Posts: 5
|
Posted: Wed Sep 22, 2004 9:50 pm Post subject: I finaly find a solution |
|
|
thank you boots for your help...
---------in the template:--------
{create_array var=$arr assign="new_arr"}
{section name=outer loop=$arr}
{splice_array var=$new_arr num=$smarty.section.outer.index assign="sp_colors"}
{section name=inner loop=$new_arr}
inside : {$new_arr[inner]} --> {$smarty.section.inner.index}
{/section}
-MAIN SECTION- {$colors[outer]} {$smarty.section.outer.index}<br>
{/section}
---------function splice------------
function smarty_function_splice_array($params, &$smarty)
{
if(!isset($params['var'])) {
$smarty->trigger_error("split_array: missing 'var' parameter");
return;
}
if(!isset($params['assign'])) {
$smarty->trigger_error("split_array: missing 'assign' parameter");
return;
}
if(!is_array($params['var'])) {
$smarty->trigger_error("split_array: expecting 'var' as an array");
return;
}
$_num = $params['num'];
$_count = count($params['var']);
$_count = $_count - $_num - 1;
$_splice_array = $params['var'];
array_splice($_splice_array,$_count,1);
$smarty->assign($params['assign'],$_splice_array);
}
?>
----------- function create ---------
function smarty_function_create_array($params, &$smarty)
{
$_splice_array = $params['var'];
$smarty->assign($params['assign'],$_splice_array);
}
?> |
|
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
|