[SMARTY] function: assign_array

From: Date: Fri, 03 May 2002 13:40:26 +0000
Subject: [SMARTY] function: assign_array
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-4026@lists.php.net to get a copy of this message
With regards to the cycle function, I think most of the time it would be used in a section to alternate row colors like: {section name=r loop=$rows} <tr bgcolor="{cycle var="row_color" values="white,silver"}"><td>{$row.val}</td></tr> {/section} So each iteration through the section it is always passing the values, and alternative syntax that might be nice to have would be the ability to call after the cycle has been initalized with just the var name. This might be used for column based color changes: {section name=r loop=$rows} <tr > <td bgcolor="{cycle var="col_color" values="white,silver,blue"}">{$row.val1}</td> <td bgcolor="{cycle var="col_color"}">{$row.val2}</td> <td bgcolor="{cycle var="col_color"}">{$row.val3}</td> <td bgcolor="{cycle var="col_color"}">{$row.val4}</td> <td bgcolor="{cycle var="col_color"}">{$row.val5}</td> <td bgcolor="{cycle var="col_color"}">{$row.val6}</td> </tr> {/section} Jason >>>>>\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: */ ?> __________________________________________________ Do You Yahoo!? Yahoo! Health - your guide to health and wellness http://health.yahoo.com

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