function: assign_array

From: Date: Fri, 03 May 2002 12:53:50 +0000
Subject: function: assign_array
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-4022@lists.php.net to get a copy of this message
Below is the function to assign an array within a template. Just in case anyone besides me needs it. :-) other topic: I think I found a little bug at function.cycle.php (line 47). I guess the triggered error must be "cycle: missing 'values' parameter" (cycle instead of assign). <?php /* * Smarty plugin * ------------------------------------------------------------- * Type: function * Name: assign_array * Version: 1.0 * Author: Jens Lehmann <jenslehmann@goldmail.de> * Credits: Monte Ohrt <monte@ispi.net> * Purpose: assign an array to a template variable * Input: var = name of the array * values = list of values (seperated by delimiter) * delimiter = value delimiter, default is "," * * Examples: {assign_array var="foo" values="bar1,bar2"} * {assign_array var="foo" values="bar1;bar2;bar3" delimiter=";"} * ------------------------------------------------------------- */ function smarty_function_assign_array($params, &$smarty) { extract($params); if(empty($delimiter)) { $delimiter = ','; } if (empty($var)) { $smarty->trigger_error("assign_array: missing 'var' parameter"); return; } if (!in_array('values', array_keys($params))) { $smarty->trigger_error("assign_array: missing 'values' parameter"); return; } $smarty->assign($var, explode($delimiter,$values) ); } /* vim: set expandtab: */ ?> Jens

« previous php.smarty.general (#4022) next »