Thread HTML::Template TMPL_IF Block in TMPL_LOOP Block (9 answers)
Opened by kruemmel at 2007-01-14 17:28

kruemmel
 2007-01-14 23:21
#73204 #73204
User since
2006-02-12
33 Artikel
BenutzerIn
[default_avatar]
ja ich benutze HTML::Template::Compiled


hier nochmal meine Scripte

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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/perl -w

use strict;
use CGI;
use DBI;
#use HTML::Template;
use HTML::Template::Compiled;


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# Datenbankdaten und Verbindung zur DB herstellen
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# Datenbank
my $datenbank = "info";
# Datenbankhost
my $datenbankhost = "127.0.0.1";
# Datenbankusername
my $datenbankuser = "root";
# Datenbankpasswort
my $datenbankpw = "";


my $dbh = DBI->connect("DBI:mysql:$datenbank:$datenbankhost","$datenbankuser","$datenbankpw")
or die "Fehler bei der Datenbankverbindung aufgetreten.";

my $CGI = CGI->new();

my $sth = $dbh->prepare('select Monat, Tag, Zeit, Host, Dienst, Meldung
from infotable');

$sth->execute();

my $rows;
push @{$rows}, $_ while $_ = $sth->fetchrow_hashref();
#push @{$rows}, {%$_, IS_DEC => $_->{Monat} eq 'Dec' ? 1 : 0} while $_ = $sth->fetchrow_hashref();

my $template = HTML::Template->new(filename => 'template1.html');
$template->param(data => $rows);

print $CGI->header();
#print "Content-Type: text/html\n\n";
print $template->output();

$dbh->disconnect();





<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">

<head>

<title><"Ergebnis von auth.log"></title>

</head>

<body>

<h1>Tabelle f&uuml;r die Datei auth.log</h1>

<table border="1">
<caption>Assoziationen</caption>
<tr>

<th>Monat</th>
<th>Tag</th>
<th>Zeit</th>
<th>Host</th>
<th>Dienst</th>
<th>Meldung</th>

</tr>

<!-- TMPL_LOOP NAME=data -->

<tr>

<td <!-- TMPL_SWITCH Monat --><!-- TMPL_CASE Dec -->style="background-color: red"<!-- /TMPL_SWITCH -->><!-- TMPL_VAR NAME=Monat --></td>
<td><!-- TMPL_VAR NAME=Tag --></td>
<td><!-- TMPL_VAR NAME=Zeit --></td>
<td><!-- TMPL_VAR NAME=Host --></td>
<td><!-- TMPL_VAR NAME=Dienst --></td>
<td><!-- TMPL_VAR NAME=Meldung --></td>

</tr>

<!-- /TMPL_LOOP -->

</table>

</body>

</html>




und hier die Fehlermeldung


Quote
[Sun Jan 14 22:12:47 2007] [error] [client 127.0.0.1] Can't locate object method "new" via package "HTML::Template" at /opt/lampp/htdocs/xampp/testperl.pl line 37.
[Sun Jan 14 22:12:47 2007] [error] [client 127.0.0.1] Premature end of script headers: testperl.pl


Die Fehlermeldung weist als Folge auf Zeile 37 im testperl.pl hin. Die Zeile 37 heisst:

my $template = HTML::Template->new(filename => 'template1.html');


Wenn ich die Variante von Renee probiere funktioniert es. Ich würde aber auch gerne Wissen warum die andere nicht funktioniert. Habe mal die Erklärung vom HTML::Template::Compiled auf CPAN gelesen und verglichen. Konnte aber keinen Fehler finden.\n\n

<!--EDIT|kruemmel|1168809990-->

View full thread HTML::Template TMPL_IF Block in TMPL_LOOP Block