Thread HTML-Template-Compiled: Mit Loop AoH ausgeben (19 answers)
Opened by GwenDragon at 2012-01-25 09:54

GwenDragon
 2012-05-04 20:01
#158077 #158077
User since
2005-01-17
14757 Artikel
Admin1
[Homepage]
user image
Sieht gut aus!

Code (perl): (dl )
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
        


DANKE!

PS: Kölner mögen mir verzeihen, dass ich sie als Beispiel verwendete. ;)
Last edited: 2012-05-04 20:09:42 +0200 (CEST)

View full thread HTML-Template-Compiled: Mit Loop AoH ausgeben