Re: [SMARTY] Building arrays within templates

From: Date: Fri, 04 Jul 2003 09:52:19 +0000
Subject: Re: [SMARTY] Building arrays within templates
References: 1 2 3 4 5  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-9838@lists.php.net to get a copy of this message
On Fri, Jul 04, 2003 at 10:38:23AM +0100, Mark Rogers wrote: > "messju mohr" writes: > > there is already sth. like that in the contrib-section of the > > smarty-website. see: > > > > http://smarty.php.net/contribs/plugins/view.php/function.assign_array.php > > I seem to recall looking at this a while back, now you remind me. What it > can;t handle (and I'm looking for) is: > {assign array="data" value="Line1"} > {assign array="data" value="Line2"} > {assign array="data" value="Line3"} > > .. which is what you'd expect > {assign var="data[]" value="Line1"} > {assign var="data[]" value="Line2"} > {assign var="data[]" value="Line3"} > > .. to do but is confusing in the array syntax, so I need a rethink anyway. > > > another plugin accomplishing this is discussed here: > > http://www.phpinsider.com/smarty-forum/viewtopic.php?t=220 > > This is a much better approach - I looked at implementing this myself but > didn't get around to it. It still doesn't handle appending to the array but > that ought to be a small tweak to the regexp to handle [] - except that > smarty uses . for arrays not [] so it isn't consistent. > > So, if: > {assign var="data.1" value="Line1"} > .. is equivalent to PHP code > $data[1] = "Line1" > .. then what would make sense as Smarty syntax for the PHP code > $data[] = "Line1" > ..? > > Logically > {assign var="data." value="Line1"} > > .. makes sense but is its meaning obvious? maybe it's most clear, if you do not put this functionality into "assign", but use two plugins "assign" and "append". this also would reflect the api of Smarty-class that has "assign" and "append". > Mark Rogers, > More Solutions Ltd

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