ePages 6.11.0 - DE_EPAGES/TLE/API/LoopHandler.pm

Package DE_EPAGES::TLE::API::LoopHandler

This tle handler provides loop/join functionalities for the tle processor. This handler supports the following tle function:

Functions

COUNT
FROMPLAINLOOP
GREP
JOIN
LOOP
SORT

COUNT

Returns count of elements.

Syntax
$Value = $Handler->COUNT( $Processor, $raParameter);
#COUNT(#Elements)
Example
#COUNT(#Products)
Input
$Processor (object)
tle processor
$raParameter (ref.array.array)
first parameter is a loop
Return
$Value (string)
return value

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
$Processor (object)
tle processor
$raParameter (ref.array)
first parameter is a loop
Return
$Value (ref.array.hash)
return value

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
#Loop (ref.array.hash)
TLE loop
#AttributeName (string)
name of an object's attribute
#Value (scalar)
value for comparison (optional)
#Operator (boolean)
operator, tle syntax, default is "EQ" (optional)
Return
#FilteredLoop (ref.array.hash)
filtered TLE loop

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
$Processor (object)
tle processor
$raParameter (ref.array)
the object
  • JoinString - string to join loop elements - string
  • LoopElements - array with loop entries - ref.array
  • Min - start element - integer
  • Max - end element - integer

$cTemplate (perl)
compiled template (template between #JOIN() and #ENDJOIN )
Return
$Value (string)
return value

LOOP

Same as a JOIN block, an empty string is used as JoinString for processed elements.

Syntax
#LOOP(#LoopElements, #Min, #Max) template #ENDLOOP
Input
$Processor (object)
tle processor
$raParameter (ref.array)
the object
  • LoopElements - array with loop entries - ref.array
  • Min - start element - integer
  • Max - end element - integer

Return
$Value (string)
return value

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
$Processor (object)
tle processor
$raParameter (ref.array.array
  • AttributeName - name of an object's attribute - string
  • ReverseDirection - reverse order, default=0 (optional) - boolean
)
first parameter is a loop
Return
$Value (string)
return value