Hello, World-2!

PET has a built-in capability called “filtering”.  Filters are modules which manipulate (preprocess) templates before they are actually processed (run).  In the following examples we will be demonstrating how it looks like!

Summary
Hello, World-2!PET has a built-in capability called “filtering”.
Including a fileUsing the filter called “general”, the following snippet includes a template.
Displaying a directoryThe following script reads in a directory and displays its content.
Multilangue support
More filtersThere are more filters, and of course you can also create your own.

Including a file

Using the filter called “general”, the following snippet includes a template.

...
{{:html_header.html}}
...

This will look for the file “html_header.html” before compiling the template, so there is no runtime penalty.

Displaying a directory

The following script reads in a directory and displays its content.  It is using the XML filter and the IO utility plugin.

<io:getDir=files dir="html/tmp"  />
[% FOREACH file = files %]
    [% file %]<br />
[% END %]

Actually the first line gets mapped to

[% file = Util.io.getDir('dir' , 'html/tmp') %]

And it displays something like this

...
file1
file2
file3
...

Multilangue support

Using (on of) the multi-language filter(s), you can do something like this

...
{{you_have}} [% subst.messagecount %] {{new_messages}}
...

In a separate .lang file, you have

...
you_have: You have
**
new_messages: new message(s).
**
..

This will output (if subst.messagecount == 5)

You have 5 new messages.

More filters

There are more filters, and of course you can also create your own.  Read Filters for more information.

Close