Package DE_EPAGES::TLE::API::LoopHandler
This tle handler provides loop/join functionalities for the tle processor. This handler supports the following tle function:
- JOIN - iterate template for loop elements, with variable join string
- LOOP - iterate template for loop elements, without join string
- COUNT - count elements
- GREP - filter elements of a loop by attribute comparison
Functions
COUNT
Returns count of elements.
Syntax |
$Value = $Handler->COUNT( $Processor, $raParameter); #COUNT(#Elements) |
Example |
#COUNT(#Products) |
Input |
|
Return |
|
FROMPLAINLOOP
Translates a plain array into an array of hashes. Each element has a hash with key "Element".
Syntax |
$Value = $Handler->FROMPLAINLOOP( $Processor, $raParameter); #FROMPLAINLOOP(#Elements) |
Example |
#FROMPLAINLOOP(#Products) |
Input |
|
Return |
|
GREP
Filters elements of an array by comparing the string value of an attribute.
Syntax |
#GREP(#Loop, #AttributeName, #Value, #Operator) |
Example |
#LOOP(#GREP(#Products, "IsVisible")) ... #ENDLOOP #LOOP(#GREP(#Products, "Name", "MyName", "NE")) ... #ENDLOOP #LOOP(#GREP(#Products, "Sub.SubSub", "5", "NGE")) ... #ENDLOOP |
Input |
|
Return |
|
JOIN
Iterate the template with elements of #LoopElements. If Min is greater then Max then the list will be processed in reverse.
Syntax |
#JOIN(#JoinString, #LoopElements, #Min, #Max) Template #ENDJOIN |
Example |
# at template #JOIN(",",#Products)#Price#ENDJOIN # implementation of a join block handler sub JOIN { my $self = shift; my ($Processor, $raParams, $cTemplate) = @_; my $JoinString = $raParams->[0]; my $Loop = $raParams->[1]; return '' if ref $Loop ne 'ARRAY'; my $Min = defined $raParams->[2] ? $raParams->[2] : 0; my $Max = defined $raParams->[3] ? $raParams->[3] : scalar @$Loop - 1; my @Content = (); foreach my $Entry (@$Loop[$Min..$Max]) { my $Element = join '', @{$Processor->replaceTLEs($cTemplate, $Entry)}; push @Content, $Element if $Element ne ''; } return join $JoinString, @Content; } |
Input |
|
Return |
|
LOOP
Same as a JOIN block, an empty string is used as JoinString for processed elements.
Syntax |
#LOOP(#LoopElements, #Min, #Max) template #ENDLOOP |
Input |
|
Return |
|
SORT
Sorts elements by an attribute (will be overwritten by Object-Cartridge).
Syntax |
$Value = $Handler->SORT( $Processor, $raParameter); #SORT(#Elements, #AttributeName, #ReverseDirection) |
Example |
#SORT(#Elements, "IsVisible") #SORT(#Elements, "IsVisible", 1) |
Input |
|
Return |
|