ePages 7.37.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
FROMHASH
FROMPLAINLOOP
GREP
JOIN
LOOP
SORT
SPLIT

COUNT

Returns the number of items in a loop

Syntax
#COUNT(#Elements)
Example
#COUNT(#Products)
Input
#Elements (ref.array.hash)
loop

FROMHASH

Translates a plain hash into an array of hashes usable iterating in template. Each element turns into a hash with keys "Key" and "Value".

Syntax
#FROMHASH(#Hash)
Example
#LOOP( #FROMHASH( #Shop.FeatureCurrentValue ) )
  #Key: #Value
#ENDLOOP
Input
#Hash (ref.hash)
hash input
Return
#Loop (ref.array.hash)
TLE loop

FROMPLAINLOOP

Translates a plain array into an array of hashes. Each element has a hash with key "Element".

Syntax
#FROMPLAINLOOP(#Elements)
Example
#LOOP( #FROMPLAINLOOP( #Products ) )
  #Element
#ENDLOOP
Input
#Elements (ref.array)
list
Return
#Loop (ref.array.hash)
TLE loop

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
#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
#JoinString (string)
string to join loop elements
#LoopElements (ref.array.hash)
array with loop entries
#Min (integer)
start element
#Max (integer)
end element

LOOP

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

Syntax
#LOOP(#LoopElements, #Min, #Max) template #ENDLOOP
Input
#LoopElements (ref.array.hash)
array with loop entries
#Min (integer)
start element
#Max (integer)
end element

SORT

Sorts elements by an attribute (will be overwritten by Object-Cartridge).

Syntax
#SORT(#Elements, #OrderBy, #Desc)
Example
#SORT(#Elements, "IsVisible")
#SORT(#Elements, "IsVisible", 1)
Input
#Elements (ref.array.hash)
TLE loop
#OrderBy (string)
hash key to order by
#Desc (boolean)
(optional, default: false) order descending if true

SPLIT

Returns an array of loop elements or an accessable hash.

Syntax
#SPLIT(#Pattern, #Text, #Alias)
Example
#LOOP( #SPLIT(" ", "Hallo Welt !") )
  #Word
#ENDLOOP
#LOCAL("Parts", #SPLIT(" ", "Hallo Welt !", 1) )
  #IF( #Parts.Hallo )
    Hallo is in parts
  #ENDIF
#ENDLOCAL
Input
#Pattern (string)
pattern to split the text
#Text (string)
text to split
#Alias (string)
use parts as alias
Return
#FilteredLoop (ref.array)
loop elements