{section}, {foreach}, associative arrays

From: Date: Thu, 08 Aug 2002 11:41:29 +0000
Subject: {section}, {foreach}, associative arrays
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-5619@lists.php.net to get a copy of this message
Hi there, i know {section} and {foreach} are just wrappers for for() and foreach(), respectively. This fact makes it impossible to use {section} with associative arrays. I think the solution could be using array_keys()... Hm, lemme give an example: Let's say I want to display the contents of $foo in {section}. The compiled code would then look like this: <pseudocode> $foo = array('a' => 'aaa', 'b' => 'bbb', 'c' => 'ccc') $keys = array_keys($loop); for ($i = 0; $i < sizeof($keys); $i++) { echo $foo[$keys[$i]]; } </pseudocode> Do you, Monte, see anything obvious this change would break? Is this likely to get implemented in a future version of Smarty? The other question I have is about {foreach}. I find the decision to have different intefaces for {section} and {foreach} pretty unfortunate. Every time I work with templates (which is not all that often), I have to take a look what the attributes are for {section}, and {foreach}: 'loop' and 'name' vs. 'from' and 'key'. (I know 'key' is something completely different from 'name' in section, but the most common usage make them pretty much equivalent in 99% of time.) Could the attribute names be unified? At least the 'from' attribute could have an alias 'loop', whaddya think? -- FreeBSD 4.6-STABLE 12:39PM up 1 day, 19:59, 11 users, load averages: 0.06, 0.05, 0.01

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