Template functions

<< Click to Display Table of Contents >>

Navigation:  Delphi HTML Report Library > Templates >

Template functions

Sections can be either functions. If a name of the section coincides with the registered function, the function applies to the entire contents of the section. For example:

{{#upper}} {{name}} {{/upper}}

 

will output a variable name in uppercase.

Functions are registered globally for the entire project:

type
 THtTemplateFunction =function(s: hstring): hstring;
procedure RegisterHtTemplateFunction(const Name: string; TF: THtTemplateFunction);Template function example

 

Consider we need to display each letter of some text in a separate box.

First we register the function:

function CharstoRects(const s: hstring): hstring;
var i: integer;
begin
 Result:='';
 for i:=1 to length(s) do 
  Result:=Result+'<div class="charrect">'+s[i]+'</div>';
end;

 

And set styles in report

.charrect {

display: inline-block;

width: 20px;

height: 20px;

border: solid black 1px;

padding: 2px;

text-align: center;

}

 

{{#charstorects}}Sample text{{/charstorects}

 

Result:

DELPHI~1_img1

Built-in functions:

uper – upper case

Lower – lower case

Trim – trim string

Include – include file

Charstorects  -see above

Padleft  - has two parameters – count of chars and text, add count spaces to left. Example: {{#padleft}}4 text{/padleft}

Date – Print current date using provided format

formatmoney - format value using # ### ### ##0.## format

formatdate - parameters: value|date format

eq - parameters A=B:C - returns C if A=B