Thread farblich dargestellte Ausgabe (15 answers)
Opened by kruemmel at 2007-01-07 21:21

renee
 2007-01-08 08:49
#72921 #72921
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Dafür wäre CPAN:HTML::Template::Compiled ganz nützlich...

Code: (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
#!/usr/bin/perl

use strict;
use warnings;
use DBI;
use HTML::Template::Compiled;

my $tmpl = 'Database.tmpl';
my $template = HTML::Template::Compiled(filename => $tmpl);

my ($user,$pass,$db,$host) = ("user","passwort","datenbank","host");
my $dbh = DBI->connect("DBI:mysql:$db:$host",$user,$pass) or die $DBI::errstr;
my $stmt = q~SELECT * FROM tabelle~;
my $sth = $dbh->prepare($stmt) or die $dbh->errstr();
$sth->execute() or die $dbh->errstr();

my @values;
while(my ($col1,$col2) = $sth->fetchrow_array()){
my $class = 0;
$class = 1 if $col2 eq 'hallo';
push @values, {VALUE => $col1, CLASS => $class};
}
$sth->finish();
$dbh->disconnect();

$template->param(SCHLEIFE => \@values);
print $template->output();



Database.tmpl:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<html>
<head>
<title>Test</title>
<style type="text/css">
.red{ color: red; }
.green{ color: green; }
</style>
</head>
<body>
<table>
<!-- TMPL_LOOP NAME=SCHLEIFE -->
<tr>
<td><img src="/pfad/zu/warndreieck.jpg"></td>
<td><span
class="<!-- TMPL_IF NAME=CLASS -->red<!-- TMPL_ELSE -->green<!-- /TMPL_IF -->">
<!-- TMPL_VAR NAME=VALUE --></span>
</td>
</tr>
<!-- /TMPL_LOOP -->
</table>
</body>
</html>
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread farblich dargestellte Ausgabe