I have an iteration, but in the ith iteration, I need it to get data from the "i-1"th container.I tried this:{iw_value name='dcr.offers.panels[i-1].anchor'/}but not luck.Thanks in advance
<iw_perl>my @list = iwpt_dcr_list('dcr.offers.panels');for (my $i = 0; $i < @list; $i++) { my $anchor = $list[$i-1]->value('anchor'); ...}</iw_perl>
For the first iteration I don't want it to take any value (or don't care what value it takes). I only need it from the 2nd iteration onwards.
Thanks for this, but I have no idea about perl, so I just pasted in what you gave me, but I get an XML Parse Error. Plese can you help with where I have gone wrong:[html] my @list = iwpt_dcr_list('dcr.offers.panels'); for (my $i = 1; $i < @list; $i++) { my $anchor = $list[$i-1]->value('anchor'); } <a name="{iw_value name='dcr.offers.panels[anchor].anchor'/}"></a>[/html]
<a name="{iw_value name='$anchor'/}"></a>
I understand all my code, and its works fine if I just ask it for the ith element, but I just dont understand this perl script to get the [i-1]th element. Please could you explain what it is doing, then I may have a chance of being about to debug it myself.
my @list = iwpt_dcr_list('dcr.offers.panels');for (my $i = 0; $i < @list; $i++) { ...}# The above is essentially identical to:# <iw_iterate var="i" list='dcr.offers.panels'># @list is an array that contains all of the nodes within dcr.offers.panels# which includes the 'anchor' node you're interested in.# The array is indexed starting at 0 the '< @list' interprets the array in# scalar context to return the number of elements in the array# so if there is only 1 node within the list, it will return '1' and you will# loop from 0 (the first element) to less-than-1 (which means once through# the loop) If you have 2 nodes that '< @list' results in 2 and you will loop # twice: i = 0 (first element), i = 1 (second element) - and so on.for (my $i = 0; $i < @list; $i++) { if ($i == 0) { # do whatever you want with the first element in the list } else { $anchor = $list[$i-1]->value('anchor'); ... iwpt_output(qq(<a name="$anchor"></a>)); ... }}# I'm not sure what you want to do with all the information# in the first iteration through the loop (the 'if' clause), but in all other# iterations through the loop (where $i > 0) we first get the value of# the 'anchor' sub-node of $list[$i - 1] (if $i = 1, the second element,# we get the value of element 0's, the first element, 'anchor' node)# You then might do some stuff ... and then you output the HTML# code you wanted ... # Note: This is inside the loop and it uses iwpt_output() and the # actual perl variable instead of an iw_value statement.# You then might do some other stuff (?)
Excelent - works really nicely. Thanks for that help, and it all makes sence. :-)What if statement would I need if I want to catch the last case, where i = number of items in the list? I've tried a few things, but to no luck.Thanks