The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

TL::Template - Template class (ja)

NAME (ja)

TL::Template::JA - �����潟����㋘�若��

SYNOPSIS

  my $t = $TL->newTemplate
    ->setTemplate(qq{
        <html>
          <title><&TITLE></title>
          
          <!begin:LOOP>
            <&LINE><br>
          <!end:LOOP>
        </html>
      });

  $t->expandAny(TITLE => 'Title');
  
  $t->node('LOOP')->add(LINE => 'line 1');
  $t->node('LOOP')->add(LINE => 'line 2');
  
  my $str = $t->toStr;
  
  # $str:
  # <html>
  #   <title>Title</title>
  #
  #
  #     line 1<br>
  #
  #     line 2<br>
  #
  # </html>

DESCRIPTION

��潟�若����������吟�ゃ�潟�������≪�������������勉����潟����㋘�若�������宴����壔�í�鴻�с�����

HTML�����<�若�˨�勐��腮帥�������潟����㋘�若����������⓾����㏍�違�í��紊������ ��������������潟�若����������吟�ゃ�潟�������≪�������������˨����障�����

�����潟����㋘�若����後�

�����㏍����壔�帥�
  <!begin:????> .... <!end:????>

begin���end��у�蚊�障�������������������若����������障����� ???? ��������壔�����������絮ゃ�勉����若����с�⓾����若�壔�с�ŝ�������違�ŝ����障�������� ��障�����begin/end ���篋ゅ勲������������絲上�������������⓾����ŝ�������������<����� ������羈���������ŝ�������違�ŝ����障��������

�����若����������〠��絎���������������㏍����壔��絲障����⓾�壔��node ��<�純��������篏睡� �����⓾�≪�壔�祉�鴻����������������堺�ャ�障����� ��障�����Template::Node ��壔�í�鴻�� add ��<�純����������若�吟�������с�������若�� ���膵違��菴������☗���������������������櫝�純�с�����

絮������帥�
  <&????>

expand/add ��<�純�������с�����絖�������絮������������贋��������絎������障�����

Include��帥�
  <!include:????>

��帥�違�勉�������贋����˨�����絎���������������<�ゃ�˨��茯㏍�粋昭��帥��絮���������障����� �����<�ゃ�˨�壔�����緇���� loadTemplate �����������<�ゃ�������勉����c�㋘�壔���� ��������勛�後嚳�����鴻�������〠�宴�������障����� loadTemplate �����若�違����⓾����ŝ����翫����壔����˨�㋘�潟�������c�㋘�壔����ŝ����� ��勛�後嚳�����鴻�������〠�宴�������障�����

Include��帥�違�壔����鴻�������☖戎����櫝�純�с����������ɱ����ʃ昆���茯㏍�粋昭����� 羂娯����˨�若����������������˨�ŝ����勉�т戎�����˨�壩絵������綽�荀���с�����

��潟����若�帥�
  <!copy:????>

????��壩�√����勉����若����������������障����� <!begin:????> .... <!end:????> ��у�蚊�障�������������勉�潟����若����ャ� ��贋�����絮���������障����� <!copy:????> ��帥�違�壔��<!begin:????> .... <!end:????> ��������� ���絮ゃ��絖���������������ゃ�潟����弱����勉����㏍����壔�����緇������˩��臀勉����ŝ������� ��ŝ����障��������

������������"flush" ���篏睡�������ŝ����翫����壔����潟����弱����勉����㏍����壔����� ��������˨����c�⓾����馹���������障��������

METHODS

$TL->newTemplate
  $t = $TL->newTemplate
  $t = $TL->newTemplate($filepath)
  $t = $TL->newTemplate($filepath, $icode)
  $t = $TL->newTemplate($filepath, $icode, $prefer_encode)

TL::Template ��ŝ����吾�с�壔�����篏������� 綣���違����������違�������勐����違�� loadTemplate ���絎�茵�������������

loadTemplate
  $t->loadTemplate($filepath)
  $t->loadTemplate($filepath, $icode)
  $t->loadTemplate($filepath, $icode, $prefer_encode)

���絎���������������<�ゃ�˨�������潟����㋘�若����������☀˛��粋昭������

$icode ��������ャ����������翫����� 'auto' ���絖���潟�若����ɱ����ゅ�ャ����ŝ����� ���絎���с��������絖���潟�若����壔��UTF-8鐚�Shift_JIS鐚�EUC-JP鐚�ISO-2022-JP���

$prefer_encode ��������˨�������� Encode �����ñ���櫝�純�ɱ�翫����� Encode ��у��������������

setTemplate
  $t->setTemplate($str)

���絎�������������絖������������潟����㋘�若����������⓾�祉��������������

node
  $child = $t->node($nodename)

���絎���������������若�������勉����若����ŝ����吾�с�壔�����菴������� 絖���������ŝ�������若��������荀�羆������������������í�若��

���絽吾��TL::Template��ŝ����吾�с�壔����������若����ŝ����吾�с�壔����勰�������壩❶��勰��������

loadTemplate��<�純�������ñ��筝��櫝�
add��<�純�������ñ���櫝�
exists
  $t->exists($nodename)

���絎������������������������ゃ����若�����絖������������ŝ��1�����������ŝ����ŝ��undef���菴�������

setAttr
  $t->setAttr(\%hash)
  $t->setAttr(%hash)

expand/add��<�純�������ф検��������若�帥�勐�������号��������絎���������� ���絎������ŝ�������勉�� plain ���絎������帥�ŝ�����

plain ��障����壩��絎���<��

$TL->escapeTag �����ñ��緇������阪��������

br

$TL->escapeTag �����ñ��緇���� ��壕����勐����� <br> ������������ <br /> �����水�ャ�������阪�����������

raw

�����勉�障�上�阪��������

js

$TL->escapeJs �����ñ��緇������阪��������

expand
  $t->expand(\%hash)
  $t->expand(%hash)

���絎������������������激�ャ�勉����若�帥�������˨��絮������帥�違��絮�������������

羝<����������������激�ャ�勉�㏍�若�勌賢��˨��絮������帥�違��絖���������ŝ�������勉�������c�⓾�� �����í�若�˨�壔�ŝ����ŝ����� 筝�������expand��勐�若�喝�冴����ф�ɱ�������勉�帥�違��罧���c����翫����壔����í�若����ŝ�����

expandAny
  $t->expandAny(\%hash)
  $t->expandAny(%hash)

expand������罕���������������潟����㋘�若�������ɱ�������勉�帥�違�������c�⓾�������í�若�������ŝ����� 篏�������toStr���茵������障�с�˨�壠����⓾�勉�帥�違��絮����������綽�荀���с�����������

add
  $t->node('foo')->add
  $t->node('foo')->add(\%hash)
  $t->node('foo')->add(%hash)

�����勉�<�純�������壔����若����ŝ����吾�с�壔����с�勉�水�ñ���櫝�純��

絖������若�����荀ŝ����若�������水�ャ�������� �����勉�<�純����������若�違�����緇���壔��絖������若����壠����������勛�倶�������祉�����

綣���違�����絎������������翫����虁Κ�����若����吾�勖�水�ュ����� expand ������������

getForm
  $form = $t->getForm($name)

HTML�����潟����㋘�若��筝㏍�勉����í�若�����茹f��������筝㏍�˨�祉�������������⓾����� �����若�帥�� TL::Form ��ŝ����吾�с�壔����勐就綣���у�������冴�����

綣���違�壔����í�若����� name="..." ��ф��絎������������������� �����ャ����������翫����壔��name絮���с�勐����������ŝ��form荀�膣������������冴�����������

setForm
  $t->setForm($form)
  $t->setForm($form, $name)

羝<�������� TL::Form ��ŝ����吾�с�壔��������HTML�����潟����㋘�若��筝㏍�勉����í�若���� 絮�������������

膃�2綣���違�壔����í�若����� name="..." ��ф��絎������������������� �����ャ����������翫����壔��name絮���с�勐����������ŝ��form荀�膣����絲乗院�����ŝ�����

�����潟����㋘�若�����絖���������������í�若����ŝ����吾�с�壔�����絖���������ŝ�� ��㏍�若�������c�������������勰����勛�倶����勉�㏍�若��絖���������⓾����� �����í�主����夌�榊�������ŝ�����

�����潟����㋘�若�����絖���������⓾�������í�若����ŝ����吾�с�壔�����絖��� �����ŝ����㏍�若�勰�≪����⓾�壔�������潟����㋘�若����勐����勉����若�帥�� 篆�絖�������������

extForm
  $t->extForm
  $t->extForm($name)

HTML�����潟����㋘�若��筝㏍�勉����í�若�����紊������≪����ŝ�宴�若�激�с�潟��絲障����������勉�с�����������������絎����������

膃�1綣���違�壔����í�若����� name="..." ��ф��絎������������������� �����ャ����������翫����壔��name絮���с�勐����������ŝ��form荀�膣����絲乗院�����ŝ�����

���絽吾�勉����í�若�����TL�����㋘�若����壔�若�壔��絲障����������勉�������⓾����������ゃ����勖��篏����茵���������������� extForm ���茵���c����翫����壔����������勖��篏����茵������ŝ�����

addHiddenForm
  $t->addHiddenForm($form)
  $t->addHiddenForm($form, $name)

羝<�������� TL::Form ��ŝ����吾�с�壔��������HTML�����潟����㋘�若��筝㏍�勉����í�若���� <input type="hidden"> 荀�膣���������☀申������������

膃�2綣���違�壔����í�若����� name="..." ��ф��絎������������������� �����ャ����������翫����壔��name絮���с�勐����������ŝ��form荀�膣����絲乗院�����ŝ�����

羝<�������������í�若�������若�帥�勐����⓾�勉�㏍�若��hidden��������☀申��������������� ��√����勐�ゃ�˩����吾����壔����������� ���膣���̬申���������������

addSessionCheck
  $t->addSessionCheck($sessiongroup)
  $t->addSessionCheck($sessiongroup, $name)
  $t->addSessionCheck($sessiongroup, $name, $issecure)

���絎���������祉����激�с�潟�違�˨�若����勉�祉����激�с��ID�����ñ����������㏍�若�������í�若�����������莨若����� ������莨若�������í�若�����POST��<�純�������с�ŝ�������違����í�若����ŝ����� ��障�����篋������˨�祉����激�с��ID�����肴��鐚�Session��壔�í�鴻��setValue鐚������⓾�ŝ�������違����í�若����ŝ����� $CGI->haveSessionCheck ��������≪�т戎������������

���絎���������祉����激�с�潟�違�˨�若�����Ini��ц┃絎�������csrfkey���綽�荀���������������ʃ┃絎���勐�翫�������í�若����ŝ����� csrfkey�����祉����激�с��ID�����ñ�������⓾�㏍�若��篏������������冴��csrfkey��壔�泣�ゃ��罸���̹�������ゃ�����������紊�������羲������ŝ����������˨�����篋����

膃�2綣���違�壔����í�若����� name="..." ��ф��絎������������������� �����ャ�����������undef������絎������������翫����壔��name絮���с�勐����������ŝ��form荀�膣����絲乗院�����ŝ�����

篏睡��筝㏍�勉�祉����激�с�潟�� mode ��� 'double' ��勐�翫����壔�� 膃�3綣���違�� 0 ��障����� 1 ������絎�������������http��眼��https��眼�����絎���с�������� �����ャ�������翫����壔�������勉�������勰��篆<�� http/https ��勉�í�<����с����������˨����c�☁�御��������������

getHtml
  $html = $t->getHtml

��劫����勉����若����勛憜����勐��絎鴻��菴�������臀勖��羝���帥�勉�帥�違�夌舟�����������⓾����������ɾ舟� ��勉�帥�違�壩�ɾ舟�����勉�障�丈����c�⓾��������

setHtml
  $t->setHtml($html)

��劫����勉����若����勛憜����勐��絎鴻��紊���眼��������"getHtml" ��◒����勐�����������������

flush
  $t->flush

�����若����勐�翫����������勉����若����勛��腴壔�障�с�� ��阪�� ��������� Template��勐�翫��������篏������阪�����������

�����潟����㋘�若����勖�����������������flush�����⓾�������ŝ�������������潟����㋘�若���� 筝�������������茲���阪�������������勉�ф絵������綽�荀����

toStr
  $str = $t->toStr

�����潟����㋘�若��(絮����腟����)������絖������������☀��������

isRoot
  $is_root = $t->isRoot

�����若����勐�翫����� undef ���菴�������Template ��勐�翫����� 1 ���菴�������

isXHTML
  $is_xhtml = $t->isXHTML

�����潟����㋘�若����� XHTML ��勉�������̬����������翫����� 1 ��������������с�ŝ����翫����� undef ���菴��������ウ絲���ŝ����с����壔�虁�������ŝ�����

Ini �����í�<�若�

��違�˨�若�������� "Template" ��с�ŝ�������違�ŝ����ŝ�����

箴�:

  [Template]
  basepath = /home/www/template/
basepath
  basepath = /home/www/template/

��後嚳�����号��絎���������堺�������ŝ�������鴻�������ュ櫝�純��

��������í�˨����� "." ��� �����ŝ����<�˨�㋘�潟�������c�㋘�壔����ŝ��

rootpath
  rootpath = /home/www/

��劫����勉����c�㋘�壔����ʒ��絮ゃ��������筝�篏���˨����������<�ゃ�˨�勉�帥�� ��≪�壔�祉�鴻��荐怨檽�������翫��������絎���������������ュ櫝�純��

��������í�˨����� "/"��� �����ŝ����≦�������<�ゃ�˨�������潟����㋘�若����������☖戎��◑┗�檽��

flush ��泣�潟����

��純�若�鴻�潟�若��

 $TL->setContentFilter('TL::Filter::Binary');
 
 my $t = $TL->newTemplate->setTemplate(
 qq{This is a header.
 
 <!begin:AAA>
   node AAA begins...
 
   <!begin:BBB>
     node BBB begins...
 
       <!begin:CCC>
       value of node CCC: <&val>
       <!end:CCC>
 
     node BBB ends...
   <!end:BBB>
 <!end:AAA>
 
 This is a footer.
 });
 
 print "\n#--- node('CCC')->add; (twice)\n";
 $t->node('AAA')->node('BBB')->node('CCC')->add(
     val => 100,
    );
 $t->node('AAA')->node('BBB')->node('CCC')->add(
     val => 200,
    );
 
 print "\n#--- node('CCC')->flush;\n";
 $t->node('AAA')->node('BBB')->node('CCC')->flush;
 
 print "\n#--- node('BBB')->add;\n";
 $t->node('AAA')->node('BBB')->add;
 
 print "\n#--- node('CCC')->add;\n";
 $t->node('AAA')->node('BBB')->node('CCC')->add(
     val => 200,
    );
 
 print "\n#--- node('CCC')->flush;\n";
 $t->node('AAA')->node('BBB')->node('CCC')->flush;
 
 print "\n#--- node('BBB')->add;\n";
 $t->node('AAA')->node('BBB')->add;
 
 print "\n#--- node('AAA')->add;\n";
 $t->node('AAA')->add;
 
 print "\n#--- root->flush;\n";
 $t->flush;

絎�茵�腟����

 #--- node('CCC')->add; (twice)
 
 #--- node('CCC')->flush;
 Content-Type: application/octet-stream
 
 This is a header.
 
 
   node AAA begins...
 
   
     node BBB begins...
 
       
       value of node CCC: 100
       
       value of node CCC: 200
       
 #--- node('BBB')->add;
 
 #--- node('CCC')->add;
 
 #--- node('CCC')->flush;
 
 
     node BBB ends...
   
     node BBB begins...
 
       
       value of node CCC: 200
       
 #--- node('BBB')->add;
 
 #--- node('AAA')->add;
 
 #--- root->flush;
 
 
     node BBB ends...
   
 
 
 This is a footer.

SEE ALSO

TL

AUTHOR INFORMATION

    Copyright 2006 YMIRLINK Inc. All Rights Reserved.

    This framework is free software; you can redistribute it and/or modify it under the same terms as Perl itself

    �����勉����㋘�若����壔�若�壔�壔����ŝ�若�純�������⓾�с�≪�с����������ŝ����� Perl �����������í�ゃ�祉�潟�鴻�� �����у�����絽������喝����眼��茵���������������堺�ャ�障�����

    Address bug reports and comments to: tl@tripletail.jp

    HP : http://tripletail.jp/