Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Presentation Templates - last item in list
ccya99
I have a multi select field on my DCT, I have the <iw_iterate> tag in my tpl. Between the selections I want a comma (,) to display on my tpl, except at the end (no comma). I tried the <iw_last> tag, but I may have done it wrong ... can someone help?
Thanks in advance.
Find more posts tagged with
Comments
mogoo
I could be wrong, but I *think* <iw_last> is only used to exit the iterate loop, i.e., you can't do anything inside <iw_last>...
When I was trying to work this problem out, here's what I did in <iw_perl>...
1. counted the characters in each replicant, adding to the count with each replicant
2. if the character count for the replicant is < 2, it was the first word on the line, so it just prints that replicant
3. otherwise, the logic inserts ", ITEM"
4. therefore, the last item in your list would be ", ITEM" -- not having a comma after it
...this might be overkill; there might be a simplier way. At any rate, here's the code. Hope it helps...
########################################################
foreach my $LIST (iwpt_dcr_list('YOURLIST')){
$YOURITEM = iwpt_dcr_value('$LIST.Name');
#incrimentally counts how many characters are in each item (+ 2 for comma and 1 space)
$prev_char_count = $char_count;
$char_count = $prev_char_count + length($YOURITEM);
#when the item is the first on a line, don't insert a comma before it
if ($prev_char_count < 3){
iwpt_output("$YOURITEM");
}
#when the item isn't the first in the list, insert a comma before it
else {
iwpt_output(", $YOURITEM");
}
}
LooseCannon
This is some 'air code' that should work:
foreach my $index (iwpt_dcr_list('dcr.List')) {
push
@temp
, iwpt_dcr_value('$index'); #load array with list values
}
push
@final
, (join ",",
@temp)
; #seperate values with commas
foreach my $val (
@final)
{
$some_output .= $val; #append values together
}
iwpt_output($some_output); #print values