* Template Toolkit [#l9a801b0]
** IF [#re14cbc9]
[% IF foo %]
..............
[% ELSIF bar %]
..............
[% ELSE %]
..............
[% END %]
** 配列 [#h9000b31]
[% users.0 %]
[% users.1 %]
** ハッシュ [#h3f8d52b]
[% pagename = 'next' %]
[% page.$pagename %] # same as [% page.next %]
http://search.cpan.org/perldoc?Template::Manual::Variables
** ループ [#g0158eb8]
[% FOREACH i IN items %]
[% i %] [% loop.index() %] # loopオブジェクトはFOREACHに標準で組み込まれたオブジェクト
[% END %]
[% WHILE (user = get_next_user_record) %]
[% user.name %]
[% END %]
*** loopオブジェクトのメソッド [#g31f8f73]
-size() number of elements in the list
-max() index number of last element (size - 1)
-index() index of current iteration from 0 to max()
-count() iteration counter from 1 to size() (i.e. index() + 1)
-first() true if the current iteration is the first
-last() true if the current iteration is the last
-prev() return the previous item in the list
-next() return the next item in the list
http://search.cpan.org/perldoc?Template::Manual::Directives
** フィルター [#dbda4fdd]
*** 改行コードをBRタグへ [#od1aad15]
<p>[% bar | html_line_break %]</p>
*** 参考 [#m48e15c0]
http://search.cpan.org/perldoc?Template::Manual::Filters
** コメント [#p71faad4]
[% # this is a comment to the end of line
foo = 'bar'
%]
[%# placing the '#' immediately inside the directive
tag comments out the entire directive
%]
http://search.cpan.org/perldoc?Template
** インクルード・インサート [#na28a551]
TTファイルをインクルード
[% INCLUDE header.tt %]
HTMLファイルをインクルード
[% INSERT "$DOC_ROOT/footer.html" %]
- $DOC_ROOTはTTをnewする時に設定しておくと良い。
- インクルードするファイルのパスは、コンフィグで相対・絶対パスの指定をする必要がある。
- http://search.cpan.org/perldoc?Template::Manual::Config
*** 参考 [#y08c5b6a]
http://search.cpan.org/perldoc?Template::Manual::Directives
** 関数 [#t08c320e]
*** 配列のjoin() [#q0688b37]
[% items.join(', ') %]
*** 配列のサイズ [#zcfcc73a]
[% results.size %]
http://search.cpan.org/perldoc?Template::Manual::VMethods