The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Ananke::Template - Front-end module to the Ananke::Template

DESCRIPTION

Based in Template ToolKit This documentation describes the Template module which is the direct Perl interface into the Ananke::Template.

SYNOPSIS

Template.pl:

        use Ananke::Template;

        # Vars
        my @array;
        push(@array,{ name => 'Udlei', last => 'Nattis' });
        push(@array,{ name => 'Ananke', last => 'IT' });

        my $var = {
                id => 1,
                title => 'no title',
                text  => 'no text',
        };

        # Template Directory and File
        my $template_dir = "./";
        my $template_file = "template.html";
        my $template_vars = {
                'hello'  => "\nhello world",
                'scalar' => $var,
                'array'  => ['v1','v2','v3','v4'],
                'register' => \@array,
        };
        $template_vars->{SCRIPT_NAME} = "file.pl";

        # Method 1 - print
        # Create template object
        my $template = new Ananke::Template($template_dir);

        # Run Template
        $template->process($template_file,$template_vars);

        # Method 2 - print
        &Ananke::Template::view_template($template_dir,$template_file,$template_vars);

        # Method 3 - write in file
        &Ananke::Template::view_template($template_dir,$template_file,$template_vars,"/tmp/file.html");

template.html:

        [% hello %]

        [% IF scalar %]
                ID: [% scalar.id %]
                Title: [% scalar.title %]
                Text: [% scalar.text %]
        [% END %]

        [% FOREACH i = array %]
                value = [% i %]
        [% END %]

        [% FOREACH i = register %]
                Nome = [% i.name %], Last = [% i.last %]
        [% END %]

DIRECTIVE

INCLUDE

Process another template file or block and include the output. Variables are localised.

        [% INCLUDE template %]
        [% INCLUDE ../template.html %]

FOREACH

Repeat the enclosed FOREACH ... END block for each value in the list.

        [% FOREACH variable = list %]                 
                content... 
                [% variable %]
        [% END %]

        # or

        [% FOREACH i = list_chn_grp %]
                [% count++ %]
                [% IF count % 2 %] [% bgcolor = "#FFFFFF" %]
                [% ELSE %] [% bgcolor = "#EEEEEE" %]
                [% END %]
        
                [% i.bgcolor %]
        [% END %]

IF / UNLESS / ELSIF / ELSE

Enclosed block is processed if the condition is true / false.

        [% IF condition %]
                content
        [% ELSIF condition %]
                content
        [% ELSE %]
                content
        [% END %]

        [% UNLESS condition %]
                content
        [% # ELSIF/ELSE as per IF, above %]
                content
        [% END %]

FOR

        [% FOR i=1;i<=12;i++ %]
                [% i=1 %]
        [% END %]

VARIABLES

        [% var = 'text' %]
        [% var %]

AUTHOR

        Udlei D. R. Nattis
        nattis@anankeit.com.br
        http://www.nobol.com.br
        http://www.anankeit.com.br