Text::CPPTemplate(3)                gedafe                Text::CPPTemplate(3)



NNAAMMEE
       Text::CPPTemplate - CPP-Style Templates

SSYYNNOOPPSSIISS
        use Text::CPPTemplate;

        my $templ = new Text::CPPTemplate('/var/web/templates','.html');

        print $templ->template({
               PAGE => 'index',
               ELEMENT => 'header',
               TITLE => 'Test'
        });

DDEESSCCRRIIPPTTIIOONN
       CPPTemplate is a templating system using a CPP-style (C Pre-Processor)
       syntax.  CPPTemplate is quite fast so that it can be used in online
       Applications such as CGI scripts to separate program the code from the
       HTML. CPPTemplate is not HTML specific, so it can be used for other
       applications. For performance reasons, the files containing the tem-
       plates are read only once and are cached for further use. This is espe-
       cially handy when working with long running scripts which use the same
       template over and over again. Apache mod_perl is such an environment.

       An application can use a large number of templates. They could for
       example represent different parts of output generated by the aplica-
       tion.  Each template can contain variables and CPP style if-then-else
       structures.  When the template gets activated, all the variables will
       get substituted and the if-then-else structures will get processed.

FFIILLEE NNAAMMEESS
       When you activate a template, you do not specify a file-name, but only
       variables. Based on the contents of some special variables, CPPTemplate
       will try to load an apropriate template file from disk. It tries to do
       this using a number of different file-names. The first one to exist
       will be used.  A directory where the templates reside and a suffix have
       to be specified with the "new" method. The following list shows which
       variables cause CPPTemplate to look for which files:

       o   _P_A_G_E___E_L_E_M_E_N_T (_P_A_G_E and _E_L_E_M_E_N_T are variables)

       o   _E_L_E_M_E_N_T

       o   _P_A_G_E

       o   "default" (as is, not a variable)

       In addition, if _T_H_E_M_E is specified, the template will be first searched
       in the subdirectory specified by that variable of the templates direc-
       tory.

       In the example given in SYNOPSIS, the following files will be opened in
       turn until one is found to exist (in the directory _/_v_a_r_/_w_e_b_/_t_e_m_p_l_a_t_e_s):
       _i_n_d_e_x___h_e_a_d_e_r_._h_t_m_l, _h_e_a_d_e_r_._h_t_m_l, _i_n_d_e_x_._h_t_m_l and _d_e_f_a_u_l_t_._h_t_m_l.

VVAARRIIAABBLLEE SSUUBBSSTTIITTUUTTIIOONN
       Variables are marked "##var##" in the templates. If no variable is
       found with that specified name, the ##var## text remains unchanged.

CCPPPP--SSTTYYLLEE DDIIRREECCTTIIVVEESS
       "MiniCPP" directives permit the selection of parts of the template
       based on some condition. The language is very very basic, it seems to
       be good-enough for most applications. The following directives are sup-
       ported:

       "// comment"
           The whole line is removed from the output

       "#ifdef VAR"
           If variable VAR is defined, the following text will be selected.

       "#if expr"
           If the expression "expr" evaluates to true (see "EXPRESSIONS"), the
           following text will be selected. You can use substitutions in the
           expression with the syntax '##VAR##'.

       "#elif expr"
           If the previous "#if" (or "#elif") expression was false, evaluate
           this "expr" and if true select the following text.

       "#else"
           If the previous "#if" (or "#elif") expression was false, select the
           following text.

       "#endif"
           Ends an "#ifdef" or an "#if".

       Note that these elements can be nested.

       The newlines will be removed unless two consecutive lines without
       MiniCPP directives are found. Spaces and tabs will be removed from the
       beginning and the end of each line. Use '\ ' (backslash space) to
       insert spaces at the beginning or the end of the line.

EEXXPPRREESSSSIIOONNSS
       At the moment only the following expressions are supported (don't laugh
       :-))

       A = B
           If A is equal to B (the text), then the expression is true.

       A ~ B
           Match A against the regular expression (perl) B. True if it does
           match, false otherwise.

EEXXAAMMPPLLEE
        #if ##ELEMENT## = ruler
        <HR>
        #elif ##ELEMENT## = buttons
          #ifdef ADD_URL
            <A href="##ADD_URL##">Add</A>
          #endif
          #ifdef PREV_URL
            <A href="##PREV_URL##">Prev</A>
          #endif
          #ifdef NEXT_URL
            <A href="##NEXT_URL##">Next</A>
          #endif
          </P>
        #endif

PPEERR--MMEETTHHOODD DDOOCCUUMMEENNTTAATTIIOONN
       "new($templates_dir, $suffix)"
           Create a new CPPTemplate object. $templates_dir is the directory
           where the templates are stored and $suffix is a text to append to
           the file-names.

       "template(\%vars)"
           Return a processed template. "\%vars" is a hashref containing the
           variables used for building the file-name, for the substitutions
           and the CPP-style directives.

SSEEEE AALLSSOO
       _T_e_x_t_:_:_T_a_g_T_e_m_p_l_a_t_e(3)

CCOOPPYYRRIIGGHHTT
       Copyright (c) 2000 ETH Zurich, All rights reserved.

LLIICCEENNSSEE
       This program is free software; you can redistribute it and/or modify it
       under the terms of the GNU General Public License as published by the
       Free Software Foundation; either version 2 of the License, or (at your
       option) any later version.

       This program is distributed in the hope that it will be useful, but
       WITHOUT ANY WARRANTY; without even the implied warranty of MER-
       CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
       Public License for more details.

       You should have received a copy of the GNU General Public License along
       with this program; if not, write to the Free Software Foundation, Inc.,
       675 Mass Ave, Cambridge, MA 02139, USA.  This library is free software;
       you can redistribute it and/or modify it under the terms of the GNU
       Lesser General Public License as published by the Free Software Founda-
       tion; either version 2.1 of the License, or (at your option) any later
       version.

AAUUTTHHOORR
       David Schweikert <dws@ee.ethz.ch>, Tobi Oetiker <oetiker@ee.ethz.ch>



0.3                               2007-03-16              Text::CPPTemplate(3)
