--------------------------------------------------
test_tmpl1.py -- Pythonでテンプレートを使う(using Cheetah)
--------------------------------------------------
#!/usr/local/bin/python
from Cheetah.Template import Template
template = Template(file='viewpy1.tmpl')
template.entry = [{'title': "entry 1", 'description': 'entry 1, blah blah'}, {'title': "entry2", 'description': 'entry 2, blah, blah'}]
print template
--------------------------------------------------
viewpy1.tmpl -- Cheetahのテンプレート
--------------------------------------------------
<html>
<head>
<title></title>
</head>
<body>
#for $i in $entry
<p>
Title: $i['title']<br />
Description: $i['description']
</p>
#end for
</body>
</html>
--------------------------------------------------
test_tmpl1.pl -- Perlでテンプレートを使う(using Template-Toolkit)
--------------------------------------------------
#!/usr/local/bin/perl
use HTML::Template;
my $template = HTML::Template->new(
filename => "viewpl1.tmpl",
);
my @entry = (
{ title => "entry 1",
description => "entry 1, blah, blah" },
{ title => "entry 2",
description => "entry 2, blah, blah" },
);
$template->param(entry => \@entry);
print $template->output();
--------------------------------------------------
viewpl1.tmpl -- Template-Toolkitのテンプレート
--------------------------------------------------
<html>
<head>
<title></title>
</head>
<body>
<TMPL_LOOP name="entry">
<p>
Title: <TMPL_VAR name="title"><br />
Description: <TMPL_VAR name="description">
</p>
</TMPL_LOOP>
</body>
</html>