1HTML::Template::FAQ(3)User Contributed Perl DocumentationHTML::Template::FAQ(3)
2
3
4

NAME

6       HTML::Template::FAQ - Frequently Asked Questions about HTML::Template
7

SYNOPSIS

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

FREQUENTLY ASKED QUESTIONS

13   Is there a place to go to discuss HTML::Template and/or get help?
14       There's a mailing-list for discussing HTML::Template at
15       html-template-users@lists.sourceforge.net. Join at:
16
17          http://lists.sourceforge.net/lists/listinfo/html-template-users
18
19       If you just want to get email when new releases are available you can
20       join the announcements mailing-list here:
21
22           http://lists.sourceforge.net/lists/listinfo/html-template-announce
23
24   Is there a searchable archive for the mailing-list?
25       Yes, you can find an archive of the SourceForge list here:
26
27           http://dir.gmane.org/gmane.comp.lang.perl.modules.html-template
28
29   I want support for <TMPL_XXX>! How about it?
30       Maybe. I definitely encourage people to discuss their ideas for
31       HTML::Template on the mailing list. Please be ready to explain to me
32       how the new tag fits in with HTML::Template's mission to provide a
33       fast, lightweight system for using HTML templates.
34
35       NOTE: Offering to program said addition and provide it in the form of a
36       patch to the most recent version of HTML::Template will definitely have
37       a softening effect on potential opponents!
38
39   I found a bug, can you fix it?
40       That depends. Did you send me the VERSION of HTML::Template, a test
41       script and a test template? If so, then almost certainly.
42
43       If you're feeling really adventurous, HTML::Template is publicly
44       available on GitHub (https://github.com/mpeters/html-template). Please
45       feel free to fork it and send me a pull request with any changes you
46       have.
47
48   <TMPL_VAR>s from the main template aren't working inside a <TMPL_LOOP>!
49       Why?
50       This is the intended behavior. "<TMPL_LOOP>" introduces a separate
51       scope for "<TMPL_VAR>s" much like a subroutine call in Perl introduces
52       a separate scope for "my" variables.
53
54       If you want your "<TMPL_VAR>"s to be global you can set the
55       "global_vars" option when you call "new()". See above for documentation
56       of the "global_vars" "new()" option.
57
58   How can I pre-load my templates using cache-mode and mod_perl?
59       Add something like this to your startup.pl:
60
61           use HTML::Template;
62           use File::Find;
63
64           print STDERR "Pre-loading HTML Templates...\n";
65           find(
66               sub {
67                   return unless /\.tmpl$/;
68                   HTML::Template->new(
69                       filename => "$File::Find::dir/$_",
70                       cache    => 1,
71                   );
72               },
73               '/path/to/templates',
74               '/another/path/to/templates/'
75           );
76
77       Note that you'll need to modify the "return unless" line to specify the
78       extension you use for your template files - I use .tmpl, as you can
79       see. You'll also need to specify the path to your template files.
80
81       One potential problem: the /path/to/templates/ must be EXACTLY the same
82       path you use when you call "HTML::Template->new()". Otherwise the cache
83       won't know they're the same file and will load a new copy - instead
84       getting a speed increase, you'll double your memory usage.  To find out
85       if this is happening set "cache_debug =" 1> in your application code
86       and look for "CACHE MISS" messages in the logs.
87
88   What characters are allowed in TMPL_* names?
89       Numbers, letters, '.', '/', '+', '-' and '_'.
90
91   How can I execute a program from inside my template?
92       Short answer: you can't. Longer answer: you shouldn't since this
93       violates the fundamental concept behind HTML::Template - that design
94       and code should be separate.
95
96       But, inevitably some people still want to do it. If that describes you
97       then you should take a look at HTML::Template::Expr. Using
98       HTML::Template::Expr it should be easy to write a "run_program()"
99       function. Then you can do awful stuff like:
100
101           <tmpl_var expr="run_program('foo.pl')">
102
103       Just, please, don't tell me about it. I'm feeling guilty enough just
104       for writing HTML::Template::Expr in the first place.
105
106   What's the best way to create a <select> form element using HTML::Template?
107       There is much disagreement on this issue. My personal preference is to
108       use CGI.pm's excellent "popup_menu()" and "scrolling_list()" functions
109       to fill in a single "<tmpl_var select_foo>" variable.
110
111       To some people this smacks of mixing HTML and code in a way that they
112       hoped HTML::Template would help them avoid. To them I'd say that HTML
113       is a violation of the principle of separating design from programming.
114       There's no clear separation between the programmatic elements of the
115       "<form>" tags and the layout of the "<form>" tags.  You'll have to draw
116       the line somewhere - clearly the designer can't be entirely in charge
117       of form creation.
118
119       It's a balancing act and you have to weigh the pros and cons on each
120       side. It is certainly possible to produce a "<select>" element entirely
121       inside the template. What you end up with is a rat's nest of loops and
122       conditionals. Alternately you can give up a certain amount of
123       flexibility in return for vastly simplifying your templates. I
124       generally choose the latter.
125
126       Another option is to investigate HTML::FillInForm which some have
127       reported success using to solve this problem.
128
129
130
131perl v5.30.1                      2020-01-30            HTML::Template::FAQ(3)
Impressum