1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
my $htc = HTML::Template::Compiled->new( filename => "$datadir/template/termine.html", tagstyle => [ qw(+php) ], loop_context_vars => 1, use_expressions => 1, ); my @row_names = qw( Datum Zeit Ort Veranstaltung); foreach my $i ( 0 .. @data - 1 ) { my ( $t ) = $data[ $i ]{ Veranstaltung } =~ s/\\n/\n/g; $textile = Text::Textile->new( disable_html => 1, flavor => 'html' ); if ( $textile ) { $data[ $i ]{ Veranstaltung } = $textile->process( $data[ $i ]{ Veranstaltung } ); } else { warn( "$PACKAGE: Problem with Textile in Code : $t" ); last; } } $htc->param( termine => { column_names => \@row_names, data => \@data } ); $str = $htc->output();
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[ { "Veranstaltung" => "C-Workshop 2020 Testdorf", "Zeit" => "12:00", "Datum" => "01.02.2012", "Ort" => "Testdorf", "Veranstalter" => "Tim Towdi" }, { "Veranstaltung" => "Perlen für Anfänger", "Zeit" => "18:00", "Datum" => "01.03.2012", "Ort" => "Perlsen", "Veranstalter" => "IHK Perlsen" } ];
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<table>
<caption>Veranstaltungen</caption>
<thead>
<tr>
<?LOOP .termine.column_names?>
<td><?= _ ?></td><?/LOOP?>
</tr>
</thead>
<tbody>
<?LOOP .termine.data alias=termin?>
<tr>
<?LOOP .termine.column_names?>
<td><?= termin._ ?></td>
<?/LOOP?>
</tr>
<?/LOOP?>
</tbody>
</table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<table>
<caption>Veranstaltungen für </caption>
<thead>
<tr>
<td>Datum</td>
<td>Zeit</td>
<td>Ort</td>
<td>Veranstaltung</td>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
1
2
3
4
5
6
7
{
"Veranstaltung" => "C-Workshop 2020 Testdorf",
"Zeit" => "12:00",
"Datum" => "01.02.2012",
"Ort" => "Testdorf",
"Veranstalter" => "Tim Towdi"
}
1
2
3
4
5
<?LOOP .termine.data alias=termin?>
<?LOOP .termine.colum_names?>
<?= termin.~_~ ?>
<?/LOOP?>
<?/LOOP?>
1
2
3
4
5
<%loop foo alias=bar %>
<%= expr=".hash{bar}" %>
<%/loop %>
<%= expr=".hash{.keyname.somewhere.in.stash}" %>
<?= EXPR="termin.{column}"?>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
#!/usr/bin/perl use strict; use warnings; use lib '.'; # load DEV of HTC use HTML::Template::Compiled; my @data = ( { Veranstaltung => "C-Workshop 2020 Testdorf", Zeit => "12:00", Datum => "01.02.2012", Ort => "Testdorf", Veranstalter => "Tim Towdi" }, { Veranstaltung => "Perlen für Anfänger", Zeit => "18:00", Datum => "01.03.2012", Ort => "Perlsen", Veranstalter => "IHK Perlsen" } ); my @row_names = qw(Veranstaltung Zeit Datum Ort Veranstalter); my $tmpl = <<HTML; <?LOOP .termine.data alias=termin?> -------------- Termin <?= __counter__ ?>: <?LOOP .termine.column_names alias=column?> <?= column ?>: <?= EXPR=".termine.data[0].{column}"?> (Datensatz 0 als Test) <?= column ?>: <?= EXPR="termin.{column}"?> <?/LOOP?> -------------- <?/LOOP?> HTML my %parms = ( termine => { column_names => \@row_names, data => \@data } ); my $htc = HTML::Template::Compiled->new( scalarref => \$tmpl, tagstyle => [qw(+php)], loop_context_vars => 1, use_expressions => 1, ); $htc->param(%parms); print $htc->output;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
#!/usr/bin/perl use 5.008; use strict; use warnings; use lib "."; use HTML::Template::Compiled; my $HTML = <<'HTML'; <?LOOP .termine.data alias=termin?> <?LOOP .termine.cols alias=col?> <?= EXPR="ucfirst(col)"?>: <?= EXPR="termin{col}"?> <?/LOOP?> <?/LOOP?> HTML my $htc = HTML::Template::Compiled->new( scalarref => \$HTML, tagstyle => [ qw(+php) ], loop_context_vars => 1, use_expressions => 1, ); $htc->param( termine => { data => [ { date => '1.1.2012', time => '11:11', event => 'Helau! Alaaaf!', location => 'Köln', storytellers => "", author => "Der Bütt" }, { date => '1.2.2012', time => '17:30', event => 'Aschermiddwoch - en Usbligg!', location => 'Kölle', storytellers => "Jo Mozz", author => "FV Oslazigg" }, ], cols => [ qw(date time event location storytellers author) ], } ); print $htc->output(); # ergibt dann: __END__ Date: 1.1.2012 Time: 11:11 Event: Helau! Alaaaf! Location: Köln Storytellers: Author: Der Bütt Date: 1.2.2012 Time: 17:30 Event: Aschermiddwoch - en Usbligg! Location: Kölle Storytellers: Jo Mozz Author: FV Oslazigg