On Tuesday 05 November 2002 14:32, Aleksey Serba wrote:
> Hello Martijn,
>
> Tuesday, November 05, 2002, 4:00:31 PM, you wrote:
>
> MvdB> On Tuesday 05 November 2002 12:31, Philip S Tellis wrote:
> >> Sometime Today, Martijn van den Burg assembled some asciibets to say:
> >> > I started using the __counter__ variable to dynamically build
> >> > JavaScript arrays in my HTML. Unfortunately __counter__ starts
> >> > counting at 1 (one), resulting in my first (i.e. index zero) array
> >> > elements not being initialized.
> >>
> >> Isn't it just easier to use arr[<tmpl_var __counter__> - 1]; ?
>
> MvdB> Easier, yes. But it results in unelegant (if not to say ugly) and
> less clear MvdB> code:
>
> MvdB> fruits[1 - 1] = new fruitObj('apple','red');
>
> MvdB> <Martijn />
>
> Instead of __counter__ you may use your own counter:
>
> foreach my $i (@arr) {
>         $i -> {my_counter} = whatever_you_want;
> }
> $template -> param( { array => \@arr } );

True of course, but I have a couple of arrays with data that are maintained 
outside the program code, in a configuration file. So either I'd have to add 
the indices manually to those arrays (and if one array entry is removed, 
renumber the remainder) or I must preprocess the arrays (adding the counter) 
before sending them off to the template.

The work-arounds are easy but I'd like a clean solution.

<Martijn />

-- 
+----------------------------------+
        Martijn van den Burg
  ASML, CS PPC Inform@tion Systems
     Voice: +31 (0)40 268 3856
+----------------------------------+



-------------------------------------------------------
This sf.net email is sponsored by: See the NEW Palm
Tungsten T handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0001en
_______________________________________________
Html-template-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/html-template-users

Reply via email to