Schrift
[thread]4575[/thread]

HTML::Template: Uebersetzung



<< >> 6 Einträge, 1 Seite
Strat
 2003-09-19 20:43
#38555 #38555
User since
2003-08-04
5246 Artikel
ModeratorIn
[Homepage] [default_avatar]
da hier einige Fragen waren zu HTML::Template, schiebe ich dies einfach mal wieder hoch.
perl -le "s::*erlco'unaty.'.dk':e,y;*kn:ai;penmic;;print"
http://www.fabiani.net/
foobar
 2003-10-02 11:32
#38556 #38556
User since
2003-08-04
69 Artikel
BenutzerIn
[default_avatar]
BTW Deutsche Umlaute sind in ISO-8859-1 enthalten, da es sich hierbei um Latin 1 handelt.
The three chief virtues of a programmer are: Laziness, Impatience and Hubris
[Larry Wall]
Strat
 2003-10-04 00:02
#38557 #38557
User since
2003-08-04
5246 Artikel
ModeratorIn
[Homepage] [default_avatar]
ich verwende im Internet normalerweise keine uncodierten Umlaute, weil die bei manchen Leuten einfach grausam aussehen, je nach System und Sprache...
perl -le "s::*erlco'unaty.'.dk':e,y;*kn:ai;penmic;;print"
http://www.fabiani.net/
Optalamia
 2003-10-02 05:52
#38558 #38558
User since
2003-10-01
50 Artikel
BenutzerIn
[Homepage] [default_avatar]
oh, kling sehr interessant, dieses Template (-:

Warum setzt DU das Ding nicht gleich ins Wiki?
Dann hätte man es doch leichter mit übersetzen - also wenn andere spontan helfen wollen und sich einen Abschnitt vornehmen.
Sollen äöüßÄÖÜ immer als aeoeuessAEOEUE geschrieben werden?
Warum?
Oder hast DU nur eine iso-8859-1-Tastatur?

Kann man denn nichts machen, um zu verhindern, daß der "normale" Text so breit gezogen wird?
Es nervt, bei jeder Zeile quer scrollen zu müssen.
Optalamia
 2003-10-03 23:52
#38559 #38559
User since
2003-10-01
50 Artikel
BenutzerIn
[Homepage] [default_avatar]
[quote=foobar,02.10.2003, 09:32][/quote]
Quote
BTW Deutsche Umlaute sind in ISO-8859-1 enthalten, da es sich hierbei um Latin 1 handelt.

Also ich meine die "englische Standard-Tastatur" ohne deutsche Umlaute. Weiß bloß nicht das Fachwort dafür. Deshalb schieb ich ISO-8859-1-Tastatur (-;
Strat
 2003-09-15 01:18
#38560 #38560
User since
2003-08-04
5246 Artikel
ModeratorIn
[Homepage] [default_avatar]
Hallo Leute,

hier uebersetze ich nach und nach die Doku zu HTML::Template nach Deutsch, damit wir das fertige vielleicht ins Wiki einbauen koennen. Wenn jemand helfen will, herzlich willkommen

perldoc HTML::Template
NAME
   HTML::Template - Perl module zur Verwendung von  HTML Templates aus CGI-Scripten (und sonstigen)

SYNOPSIS
 Zuerst erstellt man ein Template, das eine normale HTML-Datei mit einigen Sondertags, z.B. <TMPL_VAR>

Z.B. test.tmpl:
[html]
<html>
 <head><title>Test Template</title>
 <body>
   Mein Home-Verzeichnis ist <TMPL_VAR NAME=HOME>
   <p>
   Mein PATH ist auf <TMPL_VAR NAME=PATH> gesetzt.
 </body>
</html>
[/html]

Nun erstellt man ein kleines CGI-Script:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/perl
use warnings;
use strict;

use HTML::Template;

# oeffne das html-Template
my $template = HTML::Template->new(filename => 'test.tmpl'); # Fehlerabfrage: siehe unten

# Parameter einfuellen
$template->param(HOME => $ENV{HOME});
$template->param(PATH => $ENV{PATH});

# den nötigen Content-Type senden und dann das gefuellte Template ausgeben
print "Content-Type: text/html\n\n";
print $template->output;


Wenn alles im Universum ok ist, sollte man in etwa das folgende im Browser sehen, wenn man das Script ausfuehrt:
Code: (dl )
1
2
Mein Home-Verzeichnis ist /home/some/directory
Mein PATH ist auf /bin;/usr/bin gesetzt.


BESCHREIBUNG:
Dieses Modul versucht die Verwendung von HTML Templates möglichst einfach und natürlich zu machen. Es erweitert das Standard HTML mit einigen neuen HTML-Tags, z.B. <TMPL_VAR>, <TMPL_LOOP>, <TMPL_INCLUDE>, <TMPL_IF>, <TMPL_ELSE> and <TMPL_UNLESS>.

Die Datei, in der der durch diese neuen Tags erweiterte HTML-Code steht, wird Template genannt. Es wird normalerweise separat vom CGI-Script gespeichert und vielleicht sogar von jemand anderem als dem Programmierer erzeugt.

Durch die Benutzung dieses Modules fuellt man Werte in die Variablen, Schleifen und Verzweigungen, die im Template deklariert wurden. Dies gestattet, das Design (=HTML) von den Daten zu trennen, die man im Perl/CGI-Script erzeugt.

TUTORIAL:

Wenn dir HTML::Template neu ist, schlage ich vor, mit dem Einführungsartikel zu beginnen, der auf der HTML::Template-Webseite http://html-template.sourceforge.net verfügbar ist (in Englisch).

MOTIVATION:
Es gibt bereits einige Module, die mit HTML-Templates arbeiten. Einerseits existiert da CPAN:HTML::Embperl, das es einem gestattet, HTML und Perl-Code frei zu vermischen (aehnlich wie PHP und ASP, nur mit anderen Programmiersprachen), andererseits gibt es viele handgestrickte Variablenersetzungsloesungen. Hoffentlich kann dieses Modul einen goldenen Mittelweg zwischen diesen beiden Lösungswegen beschreiten.

Ein Vorteil gegenüber einer kompletten HTML::Embperl-Loesung ist, dass es eine wichtige Trennung erzwingt: Design und Programmlogik. Dadurch, dass die Programmierung nur auf einfache Variablen und Schleifen in HTML beschraenkt ist, wird das Template auch fuer Designer und andere Nicht-Perl-Programmierer verstaendlich und zugaenglich. In Zukunft koennte diese Aehnlichkeit verwendet werden, um existierende HTML-Editoren dorthingehend zu erweitern, dass sie auch HTML::Template unterstuetzen.

Ein Vorteil gegenüber handgebastelten Tag-Ersetzungsloesungen ist die Unterstuetzung fuer Schleifen. Von meinem Arbeitsgeber werde ich haeufig gefragt, HTML-Tabellen von irgendwelchen Daten zu erzeugen. Dies mit sehr einfachen HTML Templates zu machen resultiert in CGI-Scripten, die recht viel HTML enthalten, weil HTML selbst keine Unterstuetzung fuer Schleifen hat. Die Einfuehrung von Schleifenkonstrukten in das HTML vereinfacht diese Situation ganz schoen. Der Designer kann nun das Layout einer einzelnen Zeile erzeugen, und der Programmierer kann sie so oft wie noetig wiederholen und dabei Werte einfuegen. Das einzige, worin alle uebereinstimmen muessen sind die Parameternamen.

Ich denke, das beste von diesem Modul ist, dass es nur eine Sache macht, die aber dafuer schnell und sorgfaeltig. Es versucht nicht, Perl und HTML zu ersetzen, es erweitert sie beide nur ein wenig, damit sie ein bisschen besser zusammenarbeiten koennen. Und nebenbei ist es ganz schoen schnell.

DIE TAGS:
TMPL_VAR:
<TMPL_VAR NAME="PARAMETER_NAME">
Der <TMPL_VAR> Tag ist sehr einfach. Fuer jeden <TMPL_VAR> Tag im Template ruft man $template->param(PARAMETER_NAME => "WERT") auf. Wenn dann das Template ausgegeben wird, wird das <TMPL_VAR> durch den Text "WERT", den man angegeben hat. Wenn man diesen Parameter nicht setzt, wird dieser Tag im Output einfach geloescht.
Optional kann man die Option "ESCAPE=HTML" des Tags verwenden, wenn man will, dass im Wert alle HTML-Sonderzeichen durch die entsprechenden HTML-Equivalente ersetzt werden, bevor das Template ausgegeben wird (die alte Syntax mit ESCAPE=1 wird noch unterstuetzt). Das bedeutet, dass die Zeichen ", <, > und & durch &quot;, &lt;, &gt; und &amp; ersetzt werden. Dies ist nuetzlich, wenn man eine TMPL_VAR in einem Kontext verwenden will, wo diese Buchstaben Probleme bereiten koennten.

z.B.
[html]
<input name=param type=text value="<TMPL_VAR NAME="PARAM">">
[/html]
Wenn man da param() mit einem Wert wie sam"my fuettert, kommt man mit der Vorstellung von HTML, was ein doppeltes Anfuehrungszeichen ist, in Schwierigkeiten. Wenn man hingegen ESCAPE=HTML verwendet, z.B.
[html]
<input name=param type=text value="<TMPL_VAR ESCAPE=HTML NAME="PARAM">">
[/html]
dann bekommt man was man will, egal was fuer ein Wert bei param() angegeben wird.

Man kann auch folgende Schreibweisen waehlen: ESCAPE="HTML", ESCAPE='HTML' und ESCAPE='1'. Wenn man das durch eine 0 ersetzt, wird das HTML-Escaping deaktiviert, was das Standardverhalten ist.

Weiters gibt es auch noch die Option "ESCAPE=URL", die man fuer VARs benuetzt, die eine URL befuellen. In diesem Fall wird der Wert URL-Escaped, z.B. durch ersetzen von einem Leerzeichen durch '+' und von '/' durch '%2F'.

Weiters kann man einen Standardwert fuer eine Variable angeben, indem man das Attribut namens DEFAULT verwendet. Z.B. wird das folgende Beispiel den Output "Der Teufel gab mir einen Taco" produzieren, wenn die Variable WHO nicht gesetzt wird:
[html]
Der <TMPL_VAR NAME=WHO DEFAULT=Teufel> gab mir einen Taco
[/html]

TMPL_LOOP
<TMPL_LOOP NAME="LOOP_NAME"> ... </TMPL_LOOP>
Der Tag <TMPL_LOOP> ist ein bisschen komplizierter als <TMPL_VAR>. <TMPL_LOOP> erlaubt einem, einen Textabschnitt abzugrenzen und ihm einen Namen zu geben. Im Inneren dieser benannten Schleife kann man <TMPL_VAR>s plazieren.

In Perl uebergibt man param() eine Liste (genauer gesagt: eine Listenreferenz) von Parameterzuweisungen (Hashreferenzen) fuer diese Schleife. Die Schleife iteriert ueber diese Liste und produziert die Ausgabe des Textabschnittes fuer jeden Durchlauf. Nicht gesetzte Parameter werden uebersprungen.

Beispiel:
Im Template:
[html]
<TMPL_LOOP NAME=EMPLOYEE_INFO>
 Name: <TMPL_VAR NAME=NAME> <br>
 Beruf:  <TMPL_VAR NAME=JOB>  <p>
</TMPL_LOOP>
[/html]

Im Script:
Code: (dl )
1
2
3
4
5
6
7
$template->param(
 EMPLOYEE_INFO => [
   { name => 'Sam', job => 'Programmierer' },
   { name => 'Steve', job => 'Administrator' },
 ]
);
print $template->output();

Die Ausgabe im Browser sieht folgendermassen aus:
Quote
Name: Sam
Job: Programmierer

Name: Steve
Job: Administrator


<TMPL_LOOP> nimmt also eine Liste von Variablenzuweisungen entgegen und iteriert dann ueber den Schleifenkoerper und erzeugt die Ausgabe.

Haeufig wird man den Inhalt einer <TMPL_LOOP> im Programm erzeugen wollen. Hier ist einer von vielen Wegen, wie man das machen kann:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# ein paar Listen von Daten, die in die Schleife gepackt werden sollen:
my @words = qw(I Am Cool);
my @numbers = qw(1 2 3);

my @loop_data = ();  # Initialisiere eine Liste, die die Schleifendaten aufnehmen soll

while (@words and @numbers) {
 my %row_data;  # verwende einen neuen Hash fuer die Daten der Zeile
 # Fuelle die Zeile
 $row_data{WORD} = shift @words;
 $row_data{NUMBER} = shift @numbers;

 # Der kritische Punkt: werfe eine Referenz auf diese Zeile
 # auf die Schleife
 push(@loop_data, \%row_data);
}

# weise die Schleifendaten dem Schleifenparameter als Referenz zu
$template->param(THIS_LOOP => \@loop_data);

Dieses Beispiel wuerde mit einem Template wie dem folgenden funktionieren:
[html]
<TMPL_LOOP NAME="THIS_LOOP">
  Word: <TMPL_VAR NAME="WORD">     <br>
  Number: <TMPL_VAR NAME="NUMBER"> <p>
</TMPL_LOOP>
[/html]
und folgenden Output erzeugen:
Quote
      Word: I
      Number: 1

      Word: Am
      Number: 2

      Word: Cool
      Number: 3

<TMPL_LOOP>'s kann man auch verschachteln, z.B.
Code: (dl )
1
2
3
4
5
6
7
8
9
10
$template->param(
 LOOP => [
   { name => 'Bobby',
     nicknames => [
       { name => 'the big bad wolf' },
       { name => 'He-Man' },
     ],
   },
 ],
);

Grundsaetzlich ergibt jedes <TMPL_LOOP> eine Listenreferenz. In der Liste sind beliebig viele Hashreferenzen erlaubt. Diese Hashes koennen die Name=>Wert Paare fuer eine einzelne Iteration des Schleifentemplates enthalten.

Im Inneren einer <TMPL_LOOP> koennennur die Variablen der <TMPL_LOOP> verwendet werden. Die Variablen der aeusseren Bloecke sind hier nicht sichtbar.

Fuer die Computerwissenschaftler unter uns: ein <TMPL_LOOP> fuehrt ein neues lexikalisches Scope ein, aehnlich wie ein Subroutinenaufruf in Perl. Wenn man seine Variablen global haben will, kann man bei new 'global_vars' als Option angeben (wie unten beschrieben).

TMPL_INCLUDE:
 <TMPL_INCLUDE NAME="filename.tmpl">
Dieser Tag bindet ein Template direkt in das aktuelle Template ein, und zwar an der Stelle, wo dieser Tag steht. Die Inhalte des eingebundenen Templates werden genauso ausgewertet, als wuerden sie physisch an Stelle dieses Tags stehen.

Die angegebene Datei kann durch einen absoluten Pfad angegeben werden (z.B. wie unter Unix mit einem / am Anfang). Falls der Pfad nicht absolut angegeben wurde, wird als erstes der Pfad zum aktuellen Template versucht. Wenn immer noch erfolglos, wird - falls vorhanden - der Pfad, der in der Umgebungsvariablen HTML_TEMPLATE_ROOT angegeben wurde, durchsucht. Als naechstes wird die Option namens "path" abgefragt,  zuerst so, wie sie da steht, und dann mit vorangestelltem Inhalt von HTML_TEMPLATE_ROOT, wenn diese Umgebungsvariable existiert. Als letzter Versuch wird der Dateiname direkt an open() uebergeben. Fuer weitere Informationen zu HTML_TEMPLATE_ROOT siehe weiter unten und die Option "path" von new().

Als Schutz vor unendlichen rekursiven Includes wurde ein Limit von 10 Ebenen gesetzt. Mit der Option "max_includes" kann man dies veraendern.

TMPL_IF
 <TMPL_IF NAME="PARAMETER_NAME"> ... </TMPL_IF>

Der Tag <TMPL_IF> ermoeglicht es einem, einen Block in einem Template nur dann auszufuehren, wenn der Wert des Parameters "PARAMETER_NAME" wahr ist.
Die Parameter werden in derselben Weise angegeben wie mit TMPL_VAR:

Beispieltemplate:
[html]
<TMPL_IF NAME="BOOL">
 Irgendein Text, der nur dann ausgegeben wird, wenn BOOL wahr ist!
</TMPL_IF>
[/html]
Wenn man jetzt $template->param(BOOL => 1) aufruft, wird der Block zum Output hinzugefuegt.

<TMPL_IF>...</TMPL_IF>-Bloecke koennen alle gueltigen HTML-Template-Konstruktionen enthalten, z.B. VARs, LOOPs, aber auch weitere IF/ELSE-Bloecke, solange die Schachtelung korrekt bleibt. So wird das folgende nicht funktionieren:
[html]
 <TMPL_IF BOOL>
    <TMPL_LOOP SOME_LOOP>
 </TMPL_IF>
</TMPL_LOOP>
[/html]
Wenn der Name einer TMPL_LOOP in einem TMPL_IF verwendet wird, wird der IF-Block ausgegeben, wenn die LOOP mindestens eine Reihe beinhaltet, z.B.
[html]
<TMPL_IF LOOP_ONE>
 Das wird ausgegeben wenn die loop nicht leer ist
</TMPL_IF>

<TMPL_LOOP LOOP_ONE>
 ....
</TMPL_LOOP>
[/html]
Der Hauptvorteil von HTML::Template ist, dass Perl und HTML voneinander abgekoppelt werden. Wenn viele TMPL_IFs schreibt, die entsprechende if()'s in Perl haben, bekommt man wahrscheinlich ein Wartungsproblem, diese beiden if's synchron zu halten. Ich schlage vor, nur dann TMPL_IF im Template zu verwenden, wenn man es machen kann, ohne ein entsprechendes if() im Perlcode zu verwenden.

TMPL_ELSE
 <TMPL_IF NAME="PARAMETER_NAME"> ... <TMPL_ELSE> ... </TMPL_IF>

Man kann auch eine Alternative zu einem TMPL_IF-Block angeben, naemlich TMPL_ELSE.
Achtung: der Block endet trotzdem mit </TMPL_IF>, nicht mit </TMPL_ELSE> !!!
[html]
<TMPL_IF BOOL>
 Wenn BOOL wahr ist, wird das hier ausgegeben
<TMPL_ELSE>
 Wenn BOOL falsch ist, wird das hier ausgegeben
</TMPL_IF>
[/html]

TMPL_UNLESS
 <TMPL_UNLESS NAME="PARAMETER_NAME"> ... </TMPL_UNLESS>

Dieser Tag ist das Gegenteil von <TMPL_IF>. Der Block wird nur ausgegeben, wenn "PARAMETER_NAME" falsch ist (0, "", undef). <TMPL_ELSE> kann bei <TMPL_UNLESS> genauso wie bei <TMPL_IF> benuetzt werden, z.B.
[html]
<TMPL_UNLESS BOOL>
 Wenn BOOL falsch ist, wird das hier ausgegeben
<TMPL_ELSE>
 Wenn BOOL wahr ist, wird das hier ausgegeben
</TMPL_UNLESS>
[/html]
Wenn der Name einer Variable von TMPL_LOOP in einem TMPL_UNLESS verwendet wird, wird der Block dann ausgegeben, wenn die Schleife Null Zeilen enthaelt.
[html]
<TMPL_UNLESS LOOP_ONE>
 Das wird ausgegeben, wenn die LOOP leer ist.
</TMPL_UNLESS>

<TMPL_LOOP LOOP_ONE>
 ....
</TMPL_LOOP>
[/html]

Anmerkungen:

HTML::Template-Tags imitieren normale HTML-Tags. Sie duerfen jedoch die Regeln, die fuer HTML gelten, brechen, so ist z.B. das folgende nicht wirklich gueltiges HTML, aber trotzdem eine absolut zulaessige Verwendung und wird wie geplant funktionieren:
[html]
<img src="<TMPL_VAR IMAGE_SRC>">
[/html]

Das Attribut "NAME=" im Tag ist immer optional, wenngleich ich auch dringend empfehle, es immer zu verwenden.
[html]
<TMPL_LOOP LOOP_NAME>
[/html]
ist jedoch moeglich.

Wenn man unbedingt will, dass die Templates eine gueltige HTML-Syntax haben, kann man optional Templatetags in der Form von HTML-Kommentaren schreiben. Dies kann nuetzlich fuer Autoren sein, die ihre Templates schon vor der Ersetzung der Werte durch HTML::Template validieren wollen, oder DTD-basierte HTML-Editierungstools verwenden.
[html]
     <!-- TMPL_VAR NAME=PARAM1 -->
[/html]
Um gewaltige Ersparnisse bei der Uebertragungsmenge zu erziehlen, wird in diesem Dokument die Standardtagschreibweise verwendet, nicht die HTML-Kommentarschreibweise).

Methoden:

new()
Die Methode new() erzeugt ein neues HTML::Template-Objekt:
Code (perl): (dl )
1
2
3
4
5
6
7
my &#36template = HTML::Template->new( filename => 'file.tmpl',
               
               
            option => 'value'
               
               
          );

Die Methode new() muss mit mindestens einem Schlüssel-Wert-Paar aufgerufen werden, in dem angegeben wird, wie auf den Text des Templates zugegriffen werden kann. Man kann filename => 'file.tmpl' verwenden, um einen Namen einer Datei anzugeben, die als Template geoeffnet werden soll.

Weiters kann man auch eins der folgenden Konstrukte benuetzen:
Code (perl): (dl )
1
2
3
4
5
6
7
      my &#36t = HTML::Template->new( scalarref => &#36ref_to_template_text,
               
               
     option => 'value'
               
               
   );

oder
Code (perl): (dl )
1
2
3
4
5
6
7
      my &#36t = HTML::Template->new( arrayref => &#36ref_to_array_of_lines ,
               
               
     option => 'value'
               
               
   );

Diese Konstrukte initialisieren das Template aus dem Arbeitsspeicher. In fast jedem Fall will man jedoch den Parameter filename. Wenn einem die ganzen Festplattenzugriffe beim Lesen einer Template-Datei Sorgen bereiten, sollte man mod_perl und die Caching-Optionen verwenden, die weiter unten erklaert werden.

Man kann genauso ein Template von einem bereits geoeffneten Dateihandle lesen, entweder traditionell als glob oder als Filehandle:
Code (perl): (dl )
my &#36t = HTML::Template->new( filehandle => *FH, option => 'value');


Die vier folgenden Aufrufmoeglichkeiten von new() koennen genauso verwendet werden, wenn man die bevorzugt:
Code (perl): (dl )
my &#36t = HTML::Template->new_file('file.tmpl', option => 'value');

Code (perl): (dl )
1
2
3
4
my &#36t = HTML::Template->new_scalar_ref(&#36ref_to_template_text,
               
               
        option => 'value');

Code (perl): (dl )
1
2
3
4
my &#36t = HTML::Template->new_array_ref(&#36ref_to_array_of_lines,
               
               
       option => 'value');

Code (perl): (dl )
1
2
3
4
my &#36t = HTML::Template->new_filehandle(&#36fh,
               
               
       option => 'value');

Und als letzte Option kann man auch folgenden Aufruf verwenden:
Code (perl): (dl )
1
2
3
my &#36t = HTML::Template->new(type => 'filename',
               
             source => 'file.tmpl');

Dies funktioniert fuer alle drei Quellen

Wenn die Umgebugsvariable HTML_TEMPLATE_ROOT gesetzt ist und der Dateiname der Template-Datei nicht mit einem / beginnt, dann wird angenommen, dass der Pfad in filename relativ zum Wert von HTML__TEMPLATE_ROOT ist.

Wenn z.B. die Umgebungsvariable HTML_TEMPLATE_ROOT auf "/home/sam" gesetzt ist und man HTML::Template->new() mit filename "sam.tmpl" aufruft, wird versucht, das Template "/home/sam/sam.tmpl" zu lesen.

Den Template-Suchpfad kann man auch mit der option "path" von new() beeinflussen. Weiter unten gibt es mehr an Informationen darueber.

Das Verhalten des Template Objektes kann man beeinflussen, indem man in new() weitere Optionen angibt:

Optionen zur Fehlerbehandlung:
* die_on_bad_params - Falls dies auf 0 gesetzt wird, kann man auch
Code (perl): (dl )
&#36template->param(parameterName => 'wert')

verwenden, sogar wenn parameterName nicht im Template existiert. Der Standardwert ist 1.

* strict - Falls dieser Parameter auf den Wert 0 gesetzt wird, ist es auch erlaubt, Konstrukte zu verwenden, die aussehen, als waeren sie TMPL_* Tags, ohne dass das Programm stirbt, z.B. wuerde
[html]
<TMPL_HUH NAME=ZUH>
[/html]
normalerweise einen Fehler ausloesen, aber wenn man "strict" auf 0 setzt, wird es von HTML::Template ignoriert. Der
Standardwert ist 1

* vanguard_compatibility_mode - wenn dies auf 1 gesetzt wird, erwartet das Modul auch, <TMPL_VAR>s auch in der Form %NAME% vorzufinden.  Dadurch wird uebrigens  die_on_bad_params auf 0 gesetzt. Wenn man nicht bei Vanguard Media ist und nicht versucht, ein Template in diesem alten Format zu verwenden, sollte man diese Option ignorieren. Der Standardwert ist 0.

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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
    Caching Options

       *   cache - if set to 1 the module will cache in memory the parsed
           templates based on the filename parameter and modification date
           of the file. This only applies to templates opened with the
           filename parameter specified, not scalarref or arrayref
           templates. Caching also looks at the modification times of any
           files included using <TMPL_INCLUDE> tags, but again, only if the
           template is opened with filename parameter.

           This is mainly of use in a persistent environment like
           Apache/mod_perl. It has absolutely no benefit in a normal CGI
           environment since the script is unloaded from memory after every
           request. For a cache that does work for normal CGIs see the
           'shared_cache' option below.

           Note that different new() parameter settings do not cause a
           cache refresh, only a change in the modification time of the
           template will trigger a cache refresh. For most usages this is
           fine. My simplistic testing shows that using cache yields a 90%
           performance increase under mod_perl. Cache defaults to 0.

       *   shared_cache - if set to 1 the module will store its cache in
           shared memory using the IPC::SharedCache module (available from
           CPAN). The effect of this will be to maintain a single shared
           copy of each parsed template for all instances of HTML::Template
           to use. This can be a significant reduction in memory usage in a
           multiple server environment. As an example, on one of our
           systems we use 4MB of template cache and maintain 25 httpd
           processes - shared_cache results in saving almost 100MB! Of
           course, some reduction in speed versus normal caching is to be
           expected. Another difference between normal caching and
           shared_cache is that shared_cache will work in a CGI environment
           - normal caching is only useful in a persistent environment like
           Apache/mod_perl.

           By default HTML::Template uses the IPC key 'TMPL' as a shared
           root segment (0x4c504d54 in hex), but this can be changed by
           setting the 'ipc_key' new() parameter to another 4-character or
           integer key. Other options can be used to affect the shared
           memory cache correspond to IPC::SharedCache options - ipc_mode,
           ipc_segment_size and ipc_max_size. See IPC::SharedCache for a
           description of how these work - in most cases you shouldn't need
           to change them from the defaults.

           For more information about the shared memory cache system used
           by HTML::Template see IPC::SharedCache.

       *   double_cache - if set to 1 the module will use a combination of
           shared_cache and normal cache mode for the best possible
           caching. Of course, it also uses the most memory of all the
           cache modes. All the same ipc_* options that work with
           shared_cache apply to double_cache as well. By default
           double_cache is off.

       *   blind_cache - if set to 1 the module behaves exactly as with
           normal caching but does not check to see if the file has changed
           on each request. This option should be used with caution, but
           could be of use on high-load servers. My tests show blind_cache
           performing only 1 to 2 percent faster than cache under mod_perl.

           NOTE: Combining this option with shared_cache can result in
           stale templates stuck permanently in shared memory!

       *   file_cache - if set to 1 the module will store its cache in a
           file using the Storable module. It uses no additional memory,
           and my simplistic testing shows that it yields a 50% performance
           advantage. Like shared_cache, it will work in a CGI environment.
           Default is 0.

           If you set this option you must set the "file_cache_dir" option.
           See below for details.

           NOTE: Storable using flock() to ensure safe access to cache
           files. Using file_cache on a system or filesystem (NFS) without
           flock() support is dangerous.

       *   file_cache_dir - sets the directory where the module will store
           the cache files if file_cache is enabled. Your script will need
           write permissions to this directory. You'll also need to make
           sure the sufficient space is available to store the cache files.

       *   file_cache_dir_mode - sets the file mode for newly created
           file_cache directories and subdirectories. Defaults to 0700 for
           security but this may be inconvenient if you do not have access
           to the account running the webserver.

       *   double_file_cache - if set to 1 the module will use a
           combination of file_cache and normal cache mode for the best
           possible caching. The file_cache_* options that work with
           file_cache apply to double_file_cache as well. By default
           double_file_cache is 0.

   Filesystem Options

       *   path - you can set this variable with a list of paths to search
           for files specified with the "filename" option to new() and for
           files included with the <TMPL_INCLUDE> tag. This list is only
           consulted when the filename is relative. The HTML_TEMPLATE_ROOT
           environment variable is always tried first if it exists. Also,
           if HTML_TEMPLATE_ROOT is set then an attempt will be made to
           prepend HTML_TEMPLATE_ROOT onto paths in the path array. In the
           case of a <TMPL_INCLUDE> file, the path to the including file is
           also tried before path is consulted.

           Example:

              my $template = HTML::Template->new( filename => 'file.tmpl',
                                                  path => [ '/path/to/templates',
                                                            '/alternate/path'
                                                          ]
                                                 );

           NOTE: the paths in the path list must be expressed as UNIX
           paths, separated by the forward-slash character ('/').

       *   search_path_on_include - if set to a true value the module will
           search from the top of the array of paths specified by the path
           option on every <TMPL_INCLUDE> and use the first matching
           template found. The normal behavior is to look only in the
           current directory for a template to include. Defaults to 0.

   Debugging Options

       *   debug - if set to 1 the module will write random debugging
           information to STDERR. Defaults to 0.

       *   stack_debug - if set to 1 the module will use Data::Dumper to
           print out the contents of the parse_stack to STDERR. Defaults to
           0.

       *   cache_debug - if set to 1 the module will send information on
           cache loads, hits and misses to STDERR. Defaults to 0.

       *   shared_cache_debug - if set to 1 the module will turn on the
           debug option in IPC::SharedCache - see IPC::SharedCache for
           details. Defaults to 0.

       *   memory_debug - if set to 1 the module will send information on
           cache memory usage to STDERR. Requires the GTop module. Defaults
           to 0.

   Miscellaneous Options

       *   associate - this option allows you to inherit the parameter
           values from other objects. The only requirement for the other
           object is that it have a param() method that works like
           HTML::Template's param(). A good candidate would be a CGI.pm
           query object. Example:

             my $query = new CGI;
             my $template = HTML::Template->new(filename => 'template.tmpl',
                                                associate => $query);

           Now, $template->output() will act as though

             $template->param('FormField', $cgi->param('FormField'));

           had been specified for each key/value pair that would be
           provided by the $cgi->param() method. Parameters you set
           directly take precedence over associated parameters.

           You can specify multiple objects to associate by passing an
           anonymous array to the associate option. They are searched for
           parameters in the order they appear:

             my $template = HTML::Template->new(filename => 'template.tmpl',
                                                associate => [$query, $other_obj]);

           The old associateCGI() call is still supported, but should be
           considered obsolete.

           NOTE: The parameter names are matched in a case-insensitve
           manner. If you have two parameters in a CGI object like 'NAME'
           and 'Name' one will be chosen randomly by associate. This
           behavior can be changed by the following option.

       *   case_sensitive - setting this option to true causes
           HTML::Template to treat template variable names
           case-sensitively. The following example would only set one
           parameter without the "case_sensitive" option:

             my $template = HTML::Template->new(filename => 'template.tmpl',
                                                case_sensitive => 1);
             $template->param(
               FieldA => 'foo',
               fIELDa => 'bar',
             );

           This option defaults to off.

           NOTE: with case_sensitive and loop_context_vars the special loop
           variables are available in lower-case only.

       *   loop_context_vars - when this parameter is set to true (it is
           false by default) four loop context variables are made available
           inside a loop: , , , . They can
           be used with <TMPL_IF>, <TMPL_UNLESS> and <TMPL_ELSE> to control
           how a loop is output.

           In addition to the above, a  var is also made
           available when loop context variables are turned on.

           Example:

              <TMPL_LOOP NAME="FOO">
                 <TMPL_IF NAME="">
                   This only outputs on the first pass.
                 </TMPL_IF>

                 <TMPL_IF NAME="">
                   This outputs every other pass, on the odd passes.
                 </TMPL_IF>

                 <TMPL_UNLESS NAME="">
                   This outputs every other pass, on the even passes.
                 </TMPL_IF>

                 <TMPL_IF NAME="">
                   This outputs on passes that are neither first nor last.
                 </TMPL_IF>

                 This is pass number <TMPL_VAR NAME="">.

                 <TMPL_IF NAME="">
                   This only outputs on the last pass.
                 <TMPL_IF>
              </TMPL_LOOP>

           One use of this feature is to provide a "separator" similar in
           effect to the perl function join(). Example:

              <TMPL_LOOP FRUIT>
                 <TMPL_IF > and </TMPL_IF>
                 <TMPL_VAR KIND><TMPL_UNLESS >, <TMPL_ELSE>.</TMPL_UNLESS>
              </TMPL_LOOP>

           Would output (in a browser) something like:

             Apples, Oranges, Brains, Toes, and Kiwi.

           Given an appropriate param() call, of course. NOTE: A loop with
           only a single pass will get both  and  set to
           true, but not .

       *   no_includes - set this option to 1 to disallow the
           <TMPL_INCLUDE> tag in the template file. This can be used to
           make opening untrusted templates slightly less dangerous.
           Defaults to 0.

       *   max_includes - set this variable to determine the maximum depth
           that includes can reach. Set to 10 by default. Including files
           to a depth greater than this value causes an error message to be
           displayed. Set to 0 to disable this protection.

       *   global_vars - normally variables declared outside a loop are not
           available inside a loop. This option makes <TMPL_VAR>s like
           global variables in Perl - they have unlimited scope. This
           option also affects <TMPL_IF> and <TMPL_UNLESS>.

           Example:

             This is a normal variable: <TMPL_VAR NORMAL>.<P>

             <TMPL_LOOP NAME=FROOT_LOOP>
                Here it is inside the loop: <TMPL_VAR NORMAL><P>
             </TMPL_LOOP>

           Normally this wouldn't work as expected, since <TMPL_VAR
           NORMAL>'s value outside the loop is not available inside the
           loop.

           The global_vars option also allows you to access the values of
           an enclosing loop within an inner loop. For example, in this
           loop the inner loop will have access to the value of OUTER_VAR
           in the correct iteration:

              <TMPL_LOOP OUTER_LOOP>
                 OUTER: <TMPL_VAR OUTER_VAR>
                   <TMPL_LOOP INNER_LOOP>
                      INNER: <TMPL_VAR INNER_VAR>
                      INSIDE OUT: <TMPL_VAR OUTER_VAR>
                   </TMPL_LOOP>
              </TMPL_LOOP>

       *   filter - this option allows you to specify a filter for your
           template files. A filter is a subroutine that will be called
           after HTML::Template reads your template file but before it
           starts parsing template tags.

           In the most simple usage, you simply assign a code reference to
           the filter parameter. This subroutine will recieve a single
           arguement - a reference to a string containing the template file
           text. Here is an example that accepts templates with tags that
           look like "!!!ZAP_VAR FOO!!!" and transforms them into
           HTML::Template tags:

              my $filter = sub {
                my $text_ref = shift;
                $$text_ref =~ s/!!!ZAP_(.*?)!!!/<TMPL_$1>/g;
              };

              # open zap.tmpl using the above filter
              my $template = HTML::Template->new(filename => 'zap.tmpl',
                                                 filter => $filter);

           More complicated usages are possible. You can request that your
           filter receieve the template text as an array of lines rather
           than as a single scalar. To do that you need to specify your
           filter using a hash-ref. In this form you specify the filter
           using the "sub" key and the desired argument format using the
           "format" key. The available formats are "scalar" and "array".
           Using the "array" format will incur a performance penalty but
           may be more convenient in some situations.

              my $template = HTML::Template->new(filename => 'zap.tmpl',
                                                 filter => { sub => $filter,
                                                             format => 'array' });

           You may also have multiple filters. This allows simple filters
           to be combined for more elaborate functionality. To do this you
           specify an array of filters. The filters are applied in the
           order they are specified.

              my $template = HTML::Template->new(filename => 'zap.tmpl',
                                                 filter => [
                                                      { sub => \&decompress,
                                                        format => 'scalar' },
                                                      { sub => \&remove_spaces,
                                                        format => 'array' }
                                                   ]);

           The specified filters will be called for any TMPL_INCLUDEed
           files just as they are for the main template file.

 param()
   param() can be called in a number of ways

   1) To return a list of parameters in the template :

      my @parameter_names = $self->param();

   2) To return the value set to a param :

      my $value = $self->param('PARAM');

   3) To set the value of a parameter :

         # For simple TMPL_VARs:
         $self->param(PARAM => 'value');

         # with a subroutine reference that gets called to get the value
         # of the scalar.  The sub will recieve the template object as a
         # parameter.
         $self->param(PARAM => sub { return 'value' });

         # And TMPL_LOOPs:
         $self->param(LOOP_PARAM =>
                      [
                       { PARAM => VALUE_FOR_FIRST_PASS, ... },
                       { PARAM => VALUE_FOR_SECOND_PASS, ... }
                       ...
                      ]
                     );

   4) To set the value of a a number of parameters :

        # For simple TMPL_VARs:
        $self->param(PARAM => 'value',
                     PARAM2 => 'value'
                    );

         # And with some TMPL_LOOPs:
         $self->param(PARAM => 'value',
                      PARAM2 => 'value',
                      LOOP_PARAM =>
                      [
                       { PARAM => VALUE_FOR_FIRST_PASS, ... },
                       { PARAM => VALUE_FOR_SECOND_PASS, ... }
                       ...
                      ],
                      ANOTHER_LOOP_PARAM =>
                      [
                       { PARAM => VALUE_FOR_FIRST_PASS, ... },
                       { PARAM => VALUE_FOR_SECOND_PASS, ... }
                       ...
                      ]
                     );

   5) To set the value of a a number of parameters using a hash-ref :

         $self->param(
                      {
                         PARAM => 'value',
                         PARAM2 => 'value',
                         LOOP_PARAM =>
                         [
                           { PARAM => VALUE_FOR_FIRST_PASS, ... },
                           { PARAM => VALUE_FOR_SECOND_PASS, ... }
                           ...
                         ],
                         ANOTHER_LOOP_PARAM =>
                         [
                           { PARAM => VALUE_FOR_FIRST_PASS, ... },
                           { PARAM => VALUE_FOR_SECOND_PASS, ... }
                           ...
                         ]
                       }
                      );

 clear_params()
   Sets all the parameters to undef. Useful internally, if nowhere else!

 output()
   output() returns the final result of the template. In most situations
   you'll want to print this, like:

      print $template->output();

   When output is called each occurrence of <TMPL_VAR NAME=name> is
   replaced with the value assigned to "name" via param(). If a named
   parameter is unset it is simply replaced with ''. <TMPL_LOOPS> are
   evaluated once per parameter set, accumlating output on each pass.

   Calling output() is guaranteed not to change the state of the Template
   object, in case you were wondering. This property is mostly important
   for the internal implementation of loops.

   You may optionally supply a filehandle to print to automatically as the
   template is generated. This may improve performance and lower memory
   consumption. Example:

      $template->output(print_to => *STDOUT);

   The return value is undefined when using the "print_to" option.

 query()
   This method allow you to get information about the template structure.
   It can be called in a number of ways. The simplest usage of query is
   simply to check whether a parameter name exists in the template, using
   the "name" option:

     if ($template->query(name => 'foo')) {
       # do something if a varaible of any type
       # named FOO is in the template
     }

   This same usage returns the type of the parameter. The type is the same
   as the tag minus the leading 'TMPL_'. So, for example, a TMPL_VAR
   parameter returns 'VAR' from query().

     if ($template->query(name => 'foo') eq 'VAR') {
       # do something if FOO exists and is a TMPL_VAR
     }

   Note that the variables associated with TMPL_IFs and TMPL_UNLESSs will
   be identified as 'VAR' unless they are also used in a TMPL_LOOP, in
   which case they will return 'LOOP'.

   "query()" also allows you to get a list of parameters inside a loop (and
   inside loops inside loops). Example loop:

      <TMPL_LOOP NAME="EXAMPLE_LOOP">
        <TMPL_VAR NAME="BEE">
        <TMPL_VAR NAME="BOP">
        <TMPL_LOOP NAME="EXAMPLE_INNER_LOOP">
          <TMPL_VAR NAME="INNER_BEE">
          <TMPL_VAR NAME="INNER_BOP">
        </TMPL_LOOP>
      </TMPL_LOOP>

   And some query calls:

     # returns 'LOOP'
     $type = $template->query(name => 'EXAMPLE_LOOP');

     # returns ('bop', 'bee', 'example_inner_loop')
     @param_names = $template->query(loop => 'EXAMPLE_LOOP');

     # both return 'VAR'
     $type = $template->query(name => ['EXAMPLE_LOOP', 'BEE']);
     $type = $template->query(name => ['EXAMPLE_LOOP', 'BOP']);

     # and this one returns 'LOOP'
     $type = $template->query(name => ['EXAMPLE_LOOP',
                                       'EXAMPLE_INNER_LOOP']);

     # and finally, this returns ('inner_bee', 'inner_bop')
     @inner_param_names = $template->query(loop => ['EXAMPLE_LOOP',
                                                    'EXAMPLE_INNER_LOOP']);

     # for non existent parameter names you get undef
     # this returns undef.
     $type = $template->query(name => 'DWEAZLE_ZAPPA');

     # calling loop on a non-loop parameter name will cause an error.
     # this dies:
     $type = $template->query(loop => 'DWEAZLE_ZAPPA');

   As you can see above the "loop" option returns a list of parameter names
   and both "name" and "loop" take array refs in order to refer to
   parameters inside loops. It is an error to use "loop" with a parameter
   that is not a loop.

   Note that all the names are returned in lowercase and the types are
   uppercase.

   Just like "param()", "query()" with no arguements returns all the
   parameter names in the template at the top level.

FREQUENTLY ASKED QUESTIONS
   In the interest of greater understanding I've started a FAQ section of
   the perldocs. Please look in here before you send me email.

   1   Q: Is there a place to go to discuss HTML::Template and/or get help?

       A: There's a mailing-list for discussing HTML::Template at
       html-template-users@lists.sourceforge.net. To join:

          [URL=http://lists.sourceforge.net/lists/listinfo/html-template-users]http://lists.sourceforge.net/lists/listinfo/html-template-users[/URL]

       If you just want to get email when new releases are available you
       can join the announcements mailing-list here:

          [URL=http://lists.sourceforge.net/lists/listinfo/html-template-announce]http://lists.sourceforge.net/lists/listinfo/html-template-announce[/URL]
   
   2   Q: Is there a searchable archive for the mailing-list?

       A: Yes, you can find an archive of the SourceForge list here:

         [URL=http://www.geocrawler.com/lists/3/SourceForge/23294/0/]http://www.geocrawler.com/lists/3/SourceForge/23294/0/[/URL]

       For an archive of the old vm.com list, setup by Sean P. Scanlon,
       see:

          [URL=http://bluedot.net/mail/archive/]http://bluedot.net/mail/archive/[/URL]

   3   Q: I want support for <TMPL_XXX>! How about it?

       A: Maybe. I definitely encourage people to discuss their ideas for
       HTML::Template on the mailing list. Please be ready to explain to me
       how the new tag fits in with HTML::Template's mission to provide a
       fast, lightweight system for using HTML templates.

       NOTE: Offering to program said addition and provide it in the form
       of a patch to the most recent version of HTML::Template will
       definitely have a softening effect on potential opponents!

   4   Q: I found a bug, can you fix it?

       A: That depends. Did you send me the VERSION of HTML::Template, a
       test script and a test template? If so, then almost certainly.

       If you're feeling really adventurous, HTML::Template has a
       publically available CVS server. See below for more information in
       the PUBLIC CVS SERVER section.

   5   Q: <TMPL_VAR>s from the main template aren't working inside a
       <TMPL_LOOP>! Why?

       A: This is the intended behavior. <TMPL_LOOP> introduces a separate
       scope for <TMPL_VAR>s much like a subroutine call in Perl introduces
       a separate scope for "my" variables.

       If you want your <TMPL_VAR>s to be global you can set the
       'global_vars' option when you call new(). See above for
       documentation of the 'global_vars' new() option.

   6   Q: Why do you use /[Tt]/ instead of /t/i? It's so ugly!

       A: Simple - the case-insensitive match switch is very inefficient.
       According to _Mastering_Regular_Expressions_ from O'Reilly Press,
       /[Tt]/ is faster and more space efficient than /t/i - by as much as
       double against long strings. //i essentially does a lc() on the
       string and keeps a temporary copy in memory.

       When this changes, and it is in the 5.6 development series, I will
       gladly use //i. Believe me, I realize [Tt] is hideously ugly.

   7   Q: How can I pre-load my templates using cache-mode and mod_perl?

       A: Add something like this to your startup.pl:

          use HTML::Template;
          use File::Find;

          print STDERR "Pre-loading HTML Templates...\n";
          find(
               sub {
                 return unless /\.tmpl$/;
                 HTML::Template->new(
                                     filename => "$File::Find::dir/$_",
                                     cache => 1,
                                    );
               },
               '/path/to/templates',
               '/another/path/to/templates/'
             );

       Note that you'll need to modify the "return unless" line to specify
       the extension you use for your template files - I use .tmpl, as you
       can see. You'll also need to specify the path to your template
       files.

       One potential problem: the "/path/to/templates/" must be EXACTLY the
       same path you use when you call HTML::Template->new(). Otherwise the
       cache won't know they're the same file and will load a new copy -
       instead getting a speed increase, you'll double your memory usage.
       To find out if this is happening set cache_debug => 1 in your
       application code and look for "CACHE MISS" messages in the logs.

   8   Q: What characters are allowed in TMPL_* NAMEs?

       A: Numbers, letters, '.', '/', '+', '-' and '_'.

   9   Q: How can I execute a program from inside my template?

       A: Short answer: you can't. Longer answer: you shouldn't since this
       violates the fundamental concept behind HTML::Template - that design
       and code should be seperate.

       But, inevitably some people still want to do it. If that describes
       you then you should take a look at HTML::Template::Expr. Using
       HTML::Template::Expr it should be easy to write a run_program()
       function. Then you can do awful stuff like:

         <tmpl_var expr="run_program('foo.pl')">

       Just, please, don't tell me about it. I'm feeling guilty enough just
       for writing HTML::Template::Expr in the first place.

   10  Q: Can I get a copy of these docs in Japanese?

       A: Yes you can. See Kawai Takanori's translation at:

          [URL=http://member.nifty.ne.jp/hippo2000/perltips/html/template.htm]http://member.nifty.ne.jp/hippo2000/perltips/html/template.htm[/URL]

   11  Q: What's the best way to create a <select> form element using
       HTML::Template?

       A: There is much disagreement on this issue. My personal preference
       is to use CGI.pm's excellent popup_menu() and scrolling_list()
       functions to fill in a single <tmpl_var select_foo> variable.

       To some people this smacks of mixing HTML and code in a way that
       they hoped HTML::Template would help them avoid. To them I'd say
       that HTML is a violation of the principle of separating design from
       programming. There's no clear separation between the programmatic
       elements of the <form> tags and the layout of the <form> tags.
       You'll have to draw the line somewhere - clearly the designer can't
       be entirely in charge of form creation.

       It's a balancing act and you have to weigh the pros and cons on each
       side. It is certainly possible to produce a <select> element
       entirely inside the template. What you end up with is a rat's nest
       of loops and conditionals. Alternately you can give up a certain
       amount of flexibility in return for vastly simplifying your
       templates. I generally choose the latter.

       Another option is to investigate HTML::FillInForm which some have
       reported success using to solve this problem.


BUGS
Bisher kenne ich noch keine Bugs; wenn du einen findest, dann joine die Mailingliste und informiere uns darueber. Die HTML::Template Mainlingliste findest du, wenn du
http://lists.sourceforge.net/lists/listinfo/html-template-users besuchst.
Natuerlich kannst du mir auch direkt eine Email senden (sam@tregar.com), aber ich behalte mir das Recht vor, Bugreports an die Mailingliste weiterzuleiten.

Wenn du einen Bugreport schreibst, bitte gib alle Details an, wie z.B. die Version des Modules, ein Testscript und ein Testtemplate, die das Problem zeigen.

DANKSAGUNG
siehe die englische Originalversion auf CPAN:HTML::Template -> Credits

WEBSITE
Mehr Informationen ueber HTML::Template und andere davon abhaengige Module findet man auf http://html-template.sourceforge.net

OEFFENTLICHER CSV-SERVER:
HTML::Template ist nun über einen öffentlichen CSV-Server verfügbar, der von SourceForge (www.sourceforge.net) zur Verfuegung gestellt wird. Er ist erreichbar ueber: http://sourceforge.net/cvs/?group_id=1075.
Einfach mal ausprobieren

AUTOR:
   Sam Tregar, sam@tregar.com\n\n

<!--EDIT|Strat|1118678146-->
perl -le "s::*erlco'unaty.'.dk':e,y;*kn:ai;penmic;;print"
http://www.fabiani.net/
<< >> 6 Einträge, 1 Seite



View all threads created 2003-09-19 20:43.