Html Template by yyv15121

VIEWS: 55 PAGES: 11

More Info
									                                       HTML::Template

                                  Oscar Brito - aetheon@gmail.com


                                      6 de Dezembro de 2006




Oscar Brito - aetheon@gmail.com
HTML::Template
      ca
Descri¸˜o




             o
      Este m´dulo permite o uso simples de Templates Html numa script
                   o
      CGI. Este m´dulo foi construido de modo a proporcionar o uso
      natural e simples de Templates.




Oscar Brito - aetheon@gmail.com
HTML::Template
Funcionalidades


                a                                  o
      Existem v´rias funcionalidades dentro deste m´dulo, estando elas
                            e
      divididas em Tags e M´todos.
      Tags
      TMPL VAR : TMPL LOOP : TMPL INCLUDE : TMPL IF :
      TMPL ELSE : TMPL UNLESS : NOTES

        e
      M´todos
      new() : param() : clear params() : output() : query()




Oscar Brito - aetheon@gmail.com
HTML::Template
Tags


      TMPL VAR
      <input name=param type=text value=”<TMPL VAR
      NAME=”PARAM”>”>

      TMPL LOOP
      Template:
      <TMPL LOOP NAME=EMPLOYEE INFO>
      Name: <TMPL VAR NAME=NAME> <br>
      Job: <TMPL VAR NAME=JOB> <p>
      </TMPL LOOP>




Oscar Brito - aetheon@gmail.com
HTML::Template
Tags



      TMPL IF
      <TMPL IF NAME=”PARAMETER NAME”> ... </TMPL IF>

      TMPL IF
      <TMPL INCLUDE NAME=”filename.tmpl”>




Oscar Brito - aetheon@gmail.com
HTML::Template
 e
M´todos


      new()
          ca
      Cria¸˜o de um novo objecto Template.
      my $template = HTML::Template->new(filename => ’file.tmpl’, option
      => ’value’ );

      param()
      my value =self-¿param(’PARAM’);
      $self->param(PARAM => ’value’, PARAM2 => ’value’ );




Oscar Brito - aetheon@gmail.com
HTML::Template
 e
M´todos



      output()
      print $template->output();

      query()
      if ($template->query(name => ’foo’))
      ...




Oscar Brito - aetheon@gmail.com
HTML::Template
Exemplo
Template

      <html>
      <head>
      <h1> CATALOGO DE CDS <TMPL_VAR NAME=NOME>
      </h1>
      </head>
      <body>

      </body>
      <TMPL_LOOP NAME=CATALOG_INFO>
            <TMPL_IF NAME="SHOW">
            Autor: <TMPL_VAR NAME=AUTOR> <br>
            </TMPL_IF>
            Musica: <TMPL_VAR NAME=MUS> <hr>
      </TMPL_LOOP>
      </html>
Oscar Brito - aetheon@gmail.com
HTML::Template
Exemplo
Script


      #!/usr/bin/perl


      use CGI qw/:standard/;
      use HTML::Template;


      my $t = HTML::Template->new(filename => ’./template.tpl’,
                                  option => ’value’
                                 );


      $t->param(nome => ’teste’);


Oscar Brito - aetheon@gmail.com
HTML::Template
Exemplo
Script

      $t->param(CATALOG_INFO => [ {autor => ’quim barreiros’,
                                    show => 1,
                                    mus => ’garagem da vizinha’
                                   },
                                 {autor => ’metallica’,
                                   show => 1,
                                   mus => ’fade to black’
                                 },
                                 {autor => ’desconhecido’,
                                 show => 0,
                                 mus => ’atirei o pau ao gato’
                                 }
                               ]);
      print header,$t->output;

Oscar Brito - aetheon@gmail.com
HTML::Template
Exemplo
PrintScreen




Oscar Brito - aetheon@gmail.com
HTML::Template

								
To top