{
    "mode": "perldoc",
    "parameter": "HTML::Template",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/HTML%3A%3ATemplate/json",
    "generated": "2026-06-11T15:29:25Z",
    "synopsis": "First you make a template - this is just a normal HTML file with a few extra tags, the simplest\nbeing \"<TMPLVAR>\"\nFor example, test.tmpl:\n<html>\n<head><title>Test Template</title></head>\n<body>\nMy Home Directory is <TMPLVAR NAME=HOME>\n<p>\nMy Path is set to <TMPLVAR NAME=PATH>\n</body>\n</html>\nNow you can use it in a small CGI program:\n#!/usr/bin/perl -w\nuse HTML::Template;\n# open the html template\nmy $template = HTML::Template->new(filename => 'test.tmpl');\n# fill in some parameters\n$template->param(HOME => $ENV{HOME});\n$template->param(PATH => $ENV{PATH});\n# send the obligatory Content-Type and print the template output\nprint \"Content-Type: text/html\\n\\n\", $template->output;\nIf all is well in the universe this should show something like this in your browser when\nvisiting the CGI:\nMy Home Directory is /home/some/directory\nMy Path is set to /bin;/usr/bin",
    "sections": {
        "NAME": {
            "content": "HTML::Template - Perl module to use HTML-like templating language\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "First you make a template - this is just a normal HTML file with a few extra tags, the simplest\nbeing \"<TMPLVAR>\"\n\nFor example, test.tmpl:\n\n<html>\n<head><title>Test Template</title></head>\n<body>\nMy Home Directory is <TMPLVAR NAME=HOME>\n<p>\nMy Path is set to <TMPLVAR NAME=PATH>\n</body>\n</html>\n\nNow you can use it in a small CGI program:\n\n#!/usr/bin/perl -w\nuse HTML::Template;\n\n# open the html template\nmy $template = HTML::Template->new(filename => 'test.tmpl');\n\n# fill in some parameters\n$template->param(HOME => $ENV{HOME});\n$template->param(PATH => $ENV{PATH});\n\n# send the obligatory Content-Type and print the template output\nprint \"Content-Type: text/html\\n\\n\", $template->output;\n\nIf all is well in the universe this should show something like this in your browser when\nvisiting the CGI:\n\nMy Home Directory is /home/some/directory\nMy Path is set to /bin;/usr/bin\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module attempts to make using HTML templates simple and natural. It extends standard HTML\nwith a few new HTML-esque tags - \"<TMPLVAR>\" \"<TMPLLOOP>\", \"<TMPLINCLUDE>\", \"<TMPLIF>\",\n\"<TMPLELSE>\" and \"<TMPLUNLESS>\". The file written with HTML and these new tags is called a\ntemplate. It is usually saved separate from your script - possibly even created by someone else!\nUsing this module you fill in the values for the variables, loops and branches declared in the\ntemplate. This allows you to separate design - the HTML - from the data, which you generate in\nthe Perl script.\n\nThis module is licensed under the same terms as Perl. See the LICENSE section below for more\ndetails.\n",
            "subsections": []
        },
        "TUTORIAL": {
            "content": "If you're new to HTML::Template, I suggest you start with the introductory article available on\nPerl Monks:\n\nhttp://www.perlmonks.org/?nodeid=65642\n",
            "subsections": []
        },
        "FAQ": {
            "content": "Please see HTML::Template::FAQ\n",
            "subsections": []
        },
        "MOTIVATION": {
            "content": "It is true that there are a number of packages out there to do HTML templates. On the one hand\nyou have things like HTML::Embperl which allows you freely mix Perl with HTML. On the other hand\nlie home-grown variable substitution solutions. Hopefully the module can find a place between\nthe two.\n\nOne advantage of this module over a full HTML::Embperl-esque solution is that it enforces an\nimportant divide - design and programming. By limiting the programmer to just using simple\nvariables and loops in the HTML, the template remains accessible to designers and other non-perl\npeople. The use of HTML-esque syntax goes further to make the format understandable to others.\nIn the future this similarity could be used to extend existing HTML editors/analyzers to support\nHTML::Template.\n\nAn advantage of this module over home-grown tag-replacement schemes is the support for loops. In\nmy work I am often called on to produce tables of data in html. Producing them using simplistic\nHTML templates results in programs containing lots of HTML since the HTML itself cannot\nrepresent loops. The introduction of loop statements in the HTML simplifies this situation\nconsiderably. The designer can layout a single row and the programmer can fill it in as many\ntimes as necessary - all they must agree on is the parameter names.\n\nFor all that, I think the best thing about this module is that it does just one thing and it\ndoes it quickly and carefully. It doesn't try to replace Perl and HTML, it just augments them to\ninteract a little better. And it's pretty fast.\n",
            "subsections": []
        },
        "THE TAGS": {
            "content": "TMPLVAR\n<TMPLVAR NAME=\"PARAMETERNAME\">\n\nThe \"<TMPLVAR>\" tag is very simple. For each \"<TMPLVAR>\" tag in the template you call:\n\n$template->param(PARAMETERNAME => \"VALUE\")\n\nWhen the template is output the \"<TMPLVAR>\" is replaced with the VALUE text you specified. If\nyou don't set a parameter it just gets skipped in the output.\n\nYou can also specify the value of the parameter as a code reference in order to have \"lazy\"\nvariables. These sub routines will only be referenced if the variables are used. See \"LAZY\nVALUES\" for more information.\n\nAttributes\nThe following \"attributes\" can also be specified in template var tags:\n\n*   escape\n\nThis allows you to escape the value before it's put into the output.\n\nThis is useful when you want to use a TMPLVAR in a context where those characters would\ncause trouble. For example:\n\n<input name=param type=text value=\"<TMPLVAR PARAM>\">\n\nIf you called \"param()\" with a value like \"sam\"my\" you'll get in trouble with HTML's idea of\na double-quote. On the other hand, if you use \"escape=html\", like this:\n\n<input name=param type=text value=\"<TMPLVAR PARAM ESCAPE=HTML>\">\n\nYou'll get what you wanted no matter what value happens to be passed in for param.\n\nThe following escape values are supported:\n\n*   html\n\nReplaces the following characters with their HTML entity equivalent: \"&\", \"\"\", \"'\", \"<\",\n\">\"\n\n*   js\n\nEscapes (with a backslash) the following characters: \"\\\", \"'\", \"\"\", \"\\n\", \"\\r\"\n\n*   url\n\nURL escapes any ASCII characters except for letters, numbers, \"\", \".\" and \"-\".\n\n*   none\n\nPerforms no escaping. This is the default, but it's useful to be able to explicitly turn\noff escaping if you are using the \"defaultescape\" option.\n\n*   default\n\nWith this attribute you can assign a default value to a variable. For example, this will\noutput \"the devil gave me a taco\" if the \"who\" variable is not set.\n\n<TMPLVAR WHO DEFAULT=\"the devil\"> gave me a taco.\n\nTMPLLOOP\n<TMPLLOOP NAME=\"LOOPNAME\"> ... </TMPLLOOP>\n\nThe \"<TMPLLOOP>\" tag is a bit more complicated than \"<TMPLVAR>\". The \"<TMPLLOOP>\" tag allows\nyou to delimit a section of text and give it a name. Inside this named loop you place\n\"<TMPLVAR>\"s. Now you pass to \"param()\" a list (an array ref) of parameter assignments (hash\nrefs) for this loop. The loop iterates over the list and produces output from the text block for\neach pass. Unset parameters are skipped. Here's an example:\n\nIn the template:\n\n<TMPLLOOP NAME=EMPLOYEEINFO>\nName: <TMPLVAR NAME=NAME> <br>\nJob:  <TMPLVAR NAME=JOB>  <p>\n</TMPLLOOP>\n\nIn your Perl code:\n\n$template->param(\nEMPLOYEEINFO => [{name => 'Sam', job => 'programmer'}, {name => 'Steve', job => 'soda jerk'}]\n);\nprint $template->output();\n\nThe output is:\n\nName: Sam\nJob: programmer\n\nName: Steve\nJob: soda jerk\n\nAs you can see above the \"<TMPLLOOP>\" takes a list of variable assignments and then iterates\nover the loop body producing output.\n\nOften you'll want to generate a \"<TMPLLOOP>\"'s contents programmatically. Here's an example of\nhow this can be done (many other ways are possible!):\n\n# a couple of arrays of data to put in a loop:\nmy @words     = qw(I Am Cool);\nmy @numbers   = qw(1 2 3);\nmy @loopdata = ();              # initialize an array to hold your loop\n\nwhile (@words and @numbers) {\nmy %rowdata;      # get a fresh hash for the row data\n\n# fill in this row\n$rowdata{WORD}   = shift @words;\n$rowdata{NUMBER} = shift @numbers;\n\n# the crucial step - push a reference to this row into the loop!\npush(@loopdata, \\%rowdata);\n}\n\n# finally, assign the loop data to the loop param, again with a reference:\n$template->param(THISLOOP => \\@loopdata);\n\nThe above example would work with a template like:\n\n<TMPLLOOP NAME=\"THISLOOP\">\nWord: <TMPLVAR NAME=\"WORD\">\nNumber: <TMPLVAR NAME=\"NUMBER\">\n\n</TMPLLOOP>\n\nIt would produce output like:\n\nWord: I\nNumber: 1\n\nWord: Am\nNumber: 2\n\nWord: Cool\nNumber: 3\n\n\"<TMPLLOOP>\"s within \"<TMPLLOOP>\"s are fine and work as you would expect. If the syntax for\nthe \"param()\" call has you stumped, here's an example of a param call with one nested loop:\n\n$template->param(\nLOOP => [\n{\nname      => 'Bobby',\nnicknames => [{name => 'the big bad wolf'}, {name => 'He-Man'}],\n},\n],\n);\n\nBasically, each \"<TMPLLOOP>\" gets an array reference. Inside the array are any number of hash\nreferences. These hashes contain the name=>value pairs for a single pass over the loop template.\n\nInside a \"<TMPLLOOP>\", the only variables that are usable are the ones from the \"<TMPLLOOP>\".\nThe variables in the outer blocks are not visible within a template loop. For the\ncomputer-science geeks among you, a \"<TMPLLOOP>\" introduces a new scope much like a perl\nsubroutine call. If you want your variables to be global you can use \"globalvars\" option to\n\"new()\" described below.\n\nTMPLINCLUDE\n<TMPLINCLUDE NAME=\"filename.tmpl\">\n\nThis tag includes a template directly into the current template at the point where the tag is\nfound. The included template contents are used exactly as if its contents were physically\nincluded in the master template.\n\nThe file specified can be an absolute path (beginning with a '/' under Unix, for example). If it\nisn't absolute, the path to the enclosing file is tried first. After that the path in the\nenvironment variable \"HTMLTEMPLATEROOT\" is tried, if it exists. Next, the \"path\" option is\nconsulted, first as-is and then with \"HTMLTEMPLATEROOT\" prepended if available. As a final\nattempt, the filename is passed to \"open()\" directly. See below for more information on\n\"HTMLTEMPLATEROOT\" and the \"path\" option to \"new()\".\n\nAs a protection against infinitely recursive includes, an arbitrary limit of 10 levels deep is\nimposed. You can alter this limit with the \"maxincludes\" option. See the entry for the\n\"maxincludes\" option below for more details.\n\nTMPLIF\n<TMPLIF NAME=\"PARAMETERNAME\"> ... </TMPLIF>\n\nThe \"<TMPLIF>\" tag allows you to include or not include a block of the template based on the\nvalue of a given parameter name. If the parameter is given a value that is true for Perl - like\n'1' - then the block is included in the output. If it is not defined, or given a false value -\nlike '0' - then it is skipped. The parameters are specified the same way as with \"<TMPLVAR>\".\n\nExample Template:\n\n<TMPLIF NAME=\"BOOL\">\nSome text that only gets displayed if BOOL is true!\n</TMPLIF>\n\nNow if you call \"$template->param(BOOL => 1)\" then the above block will be included by output.\n\n\"<TMPLIF> </TMPLIF>\" blocks can include any valid HTML::Template construct - \"VAR\"s and\n\"LOOP\"s and other \"IF\"/\"ELSE\" blocks. Note, however, that intersecting a \"<TMPLIF>\" and a\n\"<TMPLLOOP>\" is invalid.\n\nNot going to work:\n<TMPLIF BOOL>\n<TMPLLOOP SOMELOOP>\n</TMPLIF>\n</TMPLLOOP>\n\nIf the name of a \"<TMPLLOOP>\" is used in a \"<TMPLIF>\", the \"IF\" block will output if the loop\nhas at least one row. Example:\n\n<TMPLIF LOOPONE>\nThis will output if the loop is not empty.\n</TMPLIF>\n\n<TMPLLOOP LOOPONE>\n....\n</TMPLLOOP>\n\nWARNING: Much of the benefit of HTML::Template is in decoupling your Perl and HTML. If you\nintroduce numerous cases where you have \"TMPLIF\"s and matching Perl \"if\"s, you will create a\nmaintenance problem in keeping the two synchronized. I suggest you adopt the practice of only\nusing \"TMPLIF\" if you can do so without requiring a matching \"if\" in your Perl code.\n\nTMPLELSE\n<TMPLIF NAME=\"PARAMETERNAME\"> ... <TMPLELSE> ... </TMPLIF>\n\nYou can include an alternate block in your \"<TMPLIF>\" block by using \"<TMPLELSE>\". NOTE: You\nstill end the block with \"</TMPLIF>\", not \"</TMPLELSE>\"!\n\nExample:\n<TMPLIF BOOL>\nSome text that is included only if BOOL is true\n<TMPLELSE>\nSome text that is included only if BOOL is false\n</TMPLIF>\n\nTMPLUNLESS\n<TMPLUNLESS NAME=\"PARAMETERNAME\"> ... </TMPLUNLESS>\n\nThis tag is the opposite of \"<TMPLIF>\". The block is output if the \"PARAMETERNAME\" is set\nfalse or not defined. You can use \"<TMPLELSE>\" with \"<TMPLUNLESS>\" just as you can with\n\"<TMPLIF>\".\n\nExample:\n<TMPLUNLESS BOOL>\nSome text that is output only if BOOL is FALSE.\n<TMPLELSE>\nSome text that is output only if BOOL is TRUE.\n</TMPLUNLESS>\n\nIf the name of a \"<TMPLLOOP>\" is used in a \"<TMPLUNLESS>\", the \"<UNLESS>\" block output if the\nloop has zero rows.\n\n<TMPLUNLESS LOOPONE>\nThis will output if the loop is empty.\n</TMPLUNLESS>\n\n<TMPLLOOP LOOPONE>\n....\n</TMPLLOOP>\n\nNOTES\nHTML::Template's tags are meant to mimic normal HTML tags. However, they are allowed to \"break\nthe rules\". Something like:\n\n<img src=\"<TMPLVAR IMAGESRC>\">\n\nis not really valid HTML, but it is a perfectly valid use and will work as planned.\n\nThe \"NAME=\" in the tag is optional, although for extensibility's sake I recommend using it.\nExample - \"<TMPLLOOP LOOPNAME>\" is acceptable.\n\nIf you're a fanatic about valid HTML and would like your templates to conform to valid HTML\nsyntax, you may optionally type template tags in the form of HTML comments. This may be of use\nto HTML authors who would like to validate their templates' HTML syntax prior to HTML::Template\nprocessing, or who use DTD-savvy editing tools.\n\n<!-- TMPLVAR NAME=PARAM1 -->\n\nIn order to realize a dramatic savings in bandwidth, the standard (non-comment) tags will be\nused throughout this documentation.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "new\nCall \"new()\" to create a new Template object:\n\nmy $template = HTML::Template->new(\nfilename => 'file.tmpl',\noption   => 'value',\n);\n\nYou must call \"new()\" with at least one \"name =\" value> pair specifying how to access the\ntemplate text. You can use \"filename => 'file.tmpl'\" to specify a filename to be opened as the\ntemplate. Alternately you can use:\n\nmy $t = HTML::Template->new(\nscalarref => $reftotemplatetext,\noption    => 'value',\n);\n\nand\n\nmy $t = HTML::Template->new(\narrayref => $reftoarrayoflines,\noption   => 'value',\n);\n\nThese initialize the template from in-memory resources. In almost every case you'll want to use\nthe filename parameter. If you're worried about all the disk access from reading a template file\njust use modperl and the cache option detailed below.\n\nYou can also read the template from an already opened filehandle, either traditionally as a glob\nor as a FileHandle:\n\nmy $t = HTML::Template->new(filehandle => *FH, option => 'value');\n\nThe four \"new()\" calling methods can also be accessed as below, if you prefer.\n\nmy $t = HTML::Template->newfile('file.tmpl', option => 'value');\n\nmy $t = HTML::Template->newscalarref($reftotemplatetext, option => 'value');\n\nmy $t = HTML::Template->newarrayref($reftoarrayoflines, option => 'value');\n\nmy $t = HTML::Template->newfilehandle($fh, option => 'value');\n\nAnd as a final option, for those that might prefer it, you can call new as:\n\nmy $t = HTML::Template->new(\ntype   => 'filename',\nsource => 'file.tmpl',\n);\n\nWhich works for all three of the source types.\n\nIf the environment variable \"HTMLTEMPLATEROOT\" is set and your filename doesn't begin with\n\"/\", then the path will be relative to the value of c<HTMLTEMPLATEROOT>.\n\nExample - if the environment variable \"HTMLTEMPLATEROOT\" is set to /home/sam and I call\n\"HTML::Template->new()\" with filename set to \"sam.tmpl\", HTML::Template will try to open\n/home/sam/sam.tmpl to access the template file. You can also affect the search path for files\nwith the \"path\" option to \"new()\" - see below for more information.\n\nYou can modify the Template object's behavior with \"new()\". The options are available:\n\nError Detection Options\n*   dieonbadparams\n\nIf set to 0 the module will let you call:\n\n$template->param(paramname => 'value')\n\neven if 'paramname' doesn't exist in the template body. Defaults to 1.\n\n*   forceuntaint\n\nIf set to 1 the module will not allow you to set unescaped parameters with tainted values.\nIf set to 2 you will have to untaint all parameters, including ones with the escape\nattribute. This option makes sure you untaint everything so you don't accidentally introduce\ne.g. cross-site-scripting (XSS) vulnerabilities. Requires taint mode. Defaults to 0.\n\n*   strict - if set to 0 the module will allow things that look like they might be TMPL* tags\nto get by without dieing. Example:\n\n<TMPLHUH NAME=ZUH>\n\nWould normally cause an error, but if you call new with \"strict => 0\" HTML::Template will\nignore it. Defaults to 1.\n\n*   vanguardcompatibilitymode\n\nIf set to 1 the module will expect to see \"<TMPLVAR>\"s that look like \"%NAME%\" in addition\nto the standard syntax. Also sets \"dieonbadparams =\" 0>. If you're not at Vanguard Media\ntrying to use an old format template don't worry about this one. Defaults to 0.\n\nCaching Options\n*   cache\n\nIf set to 1 the module will cache in memory the parsed templates based on the filename\nparameter, the modification date of the file and the options passed to \"new()\". This only\napplies to templates opened with the filename parameter specified, not scalarref or arrayref\ntemplates. Caching also looks at the modification times of any files included using\n\"<TMPLINCLUDE>\" tags, but again, only if the template is opened with filename parameter.\n\nThis is mainly of use in a persistent environment like Apache/modperl. It has absolutely no\nbenefit in a normal CGI environment since the script is unloaded from memory after every\nrequest. For a cache that does work for a non-persistent environment see the \"sharedcache\"\noption below.\n\nMy simplistic testing shows that using cache yields a 90% performance increase under\nmodperl. Cache defaults to 0.\n\n*   sharedcache\n\nIf set to 1 the module will store its cache in shared memory using the IPC::SharedCache\nmodule (available from CPAN). The effect of this will be to maintain a single shared copy of\neach parsed template for all instances of HTML::Template on the same machine to use. This\ncan be a significant reduction in memory usage in an environment with a single machine but\nmultiple servers. As an example, on one of our systems we use 4MB of template cache and\nmaintain 25 httpd processes - sharedcache results in saving almost 100MB! Of course, some\nreduction in speed versus normal caching is to be expected. Another difference between\nnormal caching and sharedcache is that sharedcache will work in a non-persistent\nenvironment (like normal CGI) - normal caching is only useful in a persistent environment\nlike Apache/modperl.\n\nBy default HTML::Template uses the IPC key 'TMPL' as a shared root segment (0x4c504d54 in\nhex), but this can be changed by setting the \"ipckey\" \"new()\" parameter to another\n4-character or integer key. Other options can be used to affect the shared memory cache\ncorrespond to IPC::SharedCache options - \"ipcmode\", \"ipcsegmentsize\" and \"ipcmaxsize\".\nSee IPC::SharedCache for a description of how these work - in most cases you shouldn't need\nto change them from the defaults.\n\nFor more information about the shared memory cache system used by HTML::Template see\nIPC::SharedCache.\n\n*   doublecache\n\nIf set to 1 the module will use a combination of \"sharedcache\" and normal cache mode for\nthe best possible caching. Of course, it also uses the most memory of all the cache modes.\nAll the same ipc* options that work with \"sharedcache\" apply to \"doublecache\" as well.\nDefaults to 0.\n\n*   blindcache\n\nIf set to 1 the module behaves exactly as with normal caching but does not check to see if\nthe file has changed on each request. This option should be used with caution, but could be\nof use on high-load servers. My tests show \"blindcache\" performing only 1 to 2 percent\nfaster than cache under modperl.\n\nNOTE: Combining this option with sharedcache can result in stale templates stuck\npermanently in shared memory!\n\n*   filecache\n\nIf set to 1 the module will store its cache in a file using the Storable module. It uses no\nadditional memory, and my simplistic testing shows that it yields a 50% performance\nadvantage. Like \"sharedcache\", it will work in a non-persistent environments (like CGI).\nDefault is 0.\n\nIf you set this option you must set the \"filecachedir\" option. See below for details.\n\nNOTE: Storable uses \"flock()\" to ensure safe access to cache files. Using \"filecache\" on a\nsystem or filesystem (like NFS) without \"flock()\" support is dangerous.\n\n*   filecachedir\n\nSets the directory where the module will store the cache files if \"filecache\" is enabled.\nYour script will need write permissions to this directory. You'll also need to make sure the\nsufficient space is available to store the cache files.\n\n*   filecachedirmode\n\nSets the file mode for newly created \"filecache\" directories and subdirectories. Defaults\nto \"0700\" for security but this may be inconvenient if you do not have access to the account\nrunning the webserver.\n\n*   doublefilecache\n\nIf set to 1 the module will use a combination of \"filecache\" and normal \"cache\" mode for\nthe best possible caching. The filecache* options that work with filecache apply to\n\"doublefilecache\" as well. Defaults to 0.\n\n*   cachelazyvars\n\nThe option tells HTML::Template to cache the values returned from code references used for\n\"TMPLVAR\"s. See \"LAZY VALUES\" for details.\n\n*   cachelazyloops\n\nThe option tells HTML::Template to cache the values returned from code references used for\n\"TMPLLOOP\"s. See \"LAZY VALUES\" for details.\n\nFilesystem Options\n*   path\n\nYou can set this variable with a list of paths to search for files specified with the\n\"filename\" option to \"new()\" and for files included with the \"<TMPLINCLUDE>\" tag. This list\nis only consulted when the filename is relative. The \"HTMLTEMPLATEROOT\" environment\nvariable is always tried first if it exists. Also, if \"HTMLTEMPLATEROOT\" is set then an\nattempt will be made to prepend \"HTMLTEMPLATEROOT\" onto paths in the path array. In the\ncase of a \"<TMPLINCLUDE>\" file, the path to the including file is also tried before path is\nconsulted.\n\nExample:\n\nmy $template = HTML::Template->new(\nfilename => 'file.tmpl',\npath     => ['/path/to/templates', '/alternate/path'],\n);\n\nNOTE: the paths in the path list must be expressed as UNIX paths, separated by the\nforward-slash character ('/').\n\n*   searchpathoninclude\n\nIf set to a true value the module will search from the top of the array of paths specified\nby the path option on every \"<TMPLINCLUDE>\" and use the first matching template found. The\nnormal behavior is to look only in the current directory for a template to include. Defaults\nto 0.\n\n*   utf8\n\nSetting this to true tells HTML::Template to treat your template files as UTF-8 encoded.\nThis will apply to any file's passed to \"new()\" or any included files. It won't do anything\nspecial to scalars templates passed to \"new()\" since you should be doing the encoding on\nthose yourself.\n\nmy $template = HTML::Template->new(\nfilename => 'umlautsareawesome.tmpl',\nutf8     => 1,\n);\n\nMost templates are either ASCII (the default) or UTF-8 encoded Unicode. But if you need some\nother encoding other than these 2, look at the \"openmode\" option.\n\nNOTE: The \"utf8\" and \"openmode\" options cannot be used at the same time.\n\n*   openmode\n\nYou can set this option to an opening mode with which all template files will be opened.\n\nFor example, if you want to use a template that is UTF-16 encoded unicode:\n\nmy $template = HTML::Template->new(\nfilename  => 'file.tmpl',\nopenmode => '<:encoding(UTF-16)',\n);\n\nThat way you can force a different encoding (than the default ASCII or UTF-8), CR/LF\nproperties etc. on the template files. See PerlIO for details.\n\nNOTE: this only works in perl 5.7.1 and above.\n\nNOTE: you have to supply an opening mode that actually permits reading from the file handle.\n\nNOTE: The \"utf8\" and \"openmode\" options cannot be used at the same time.\n\nDebugging Options\n*   debug\n\nIf set to 1 the module will write random debugging information to STDERR. Defaults to 0.\n\n*   stackdebug\n\nIf set to 1 the module will use Data::Dumper to print out the contents of the parsestack to\nSTDERR. Defaults to 0.\n\n*   cachedebug\n\nIf set to 1 the module will send information on cache loads, hits and misses to STDERR.\nDefaults to 0.\n\n*   sharedcachedebug\n\nIf set to 1 the module will turn on the debug option in IPC::SharedCache. Defaults to 0.\n\n*   memorydebug\n\nIf set to 1 the module will send information on cache memory usage to STDERR. Requires the\nGTop module. Defaults to 0.\n\nMiscellaneous Options\n*   associate\n\nThis option allows you to inherit the parameter values from other objects. The only\nrequirement for the other object is that it have a \"param()\" method that works like\nHTML::Template's \"param()\". A good candidate would be a CGI query object. Example:\n\nmy $query    = CGI->new;\nmy $template = HTML::Template->new(\nfilename  => 'template.tmpl',\nassociate => $query,\n);\n\nNow, \"$template->output()\" will act as though\n\n$template->param(formfield => $cgi->param('formfield'));\n\nhad been specified for each key/value pair that would be provided by the \"$cgi->param()\"\nmethod. Parameters you set directly take precedence over associated parameters.\n\nYou can specify multiple objects to associate by passing an anonymous array to the associate\noption. They are searched for parameters in the order they appear:\n\nmy $template = HTML::Template->new(\nfilename  => 'template.tmpl',\nassociate => [$query, $otherobj],\n);\n\nNOTE: The parameter names are matched in a case-insensitive manner. If you have two\nparameters in a CGI object like 'NAME' and 'Name' one will be chosen randomly by associate.\nThis behavior can be changed by the \"casesensitive\" option.\n\n*   casesensitive\n\nSetting this option to true causes HTML::Template to treat template variable names\ncase-sensitively. The following example would only set one parameter without the\n\"casesensitive\" option:\n\nmy $template = HTML::Template->new(\nfilename       => 'template.tmpl',\ncasesensitive => 1\n);\n$template->param(\nFieldA => 'foo',\nfIELDa => 'bar',\n);\n\nThis option defaults to off.\n\nNOTE: with \"casesensitive\" and \"loopcontextvars\" the special loop variables are available\nin lower-case only.\n\n*   loopcontextvars\n\nWhen this parameter is set to true (it is false by default) extra variables that depend on\nthe loop's context are made available inside a loop. These are:\n\n*   first\n\nValue that is true for the first iteration of the loop and false every other time.\n\n*   last\n\nValue that is true for the last iteration of the loop and false every other time.\n\n*   inner\n\nValue that is true for the every iteration of the loop except for the first and last.\n\n*   outer\n\nValue that is true for the first and last iterations of the loop.\n\n*   odd\n\nValue that is true for the every odd iteration of the loop.\n\n*   even\n\nValue that is true for the every even iteration of the loop.\n\n*   counter\n\nAn integer (starting from 1) whose value increments for each iteration of the loop.\n\n*   index\n\nAn integer (starting from 0) whose value increments for each iteration of the loop.\n\nJust like any other \"TMPLVAR\"s these variables can be used in \"<TMPLIF>\", \"<TMPLUNLESS>\"\nand \"<TMPLELSE>\" to control how a loop is output.\n\nExample:\n\n<TMPLLOOP NAME=\"FOO\">\n<TMPLIF NAME=\"first\">\nThis only outputs on the first pass.\n</TMPLIF>\n\n<TMPLIF NAME=\"odd\">\nThis outputs every other pass, on the odd passes.\n</TMPLIF>\n\n<TMPLUNLESS NAME=\"odd\">\nThis outputs every other pass, on the even passes.\n</TMPLUNLESS>\n\n<TMPLIF NAME=\"inner\">\nThis outputs on passes that are neither first nor last.\n</TMPLIF>\n\nThis is pass number <TMPLVAR NAME=\"counter\">.\n\n<TMPLIF NAME=\"last\">\nThis only outputs on the last pass.\n</TMPLIF>\n</TMPLLOOP>\n\nOne use of this feature is to provide a \"separator\" similar in effect to the perl function\n\"join()\". Example:\n\n<TMPLLOOP FRUIT>\n<TMPLIF last> and </TMPLIF>\n<TMPLVAR KIND><TMPLUNLESS last>, <TMPLELSE>.</TMPLUNLESS>\n</TMPLLOOP>\n\nWould output something like:\n\nApples, Oranges, Brains, Toes, and Kiwi.\n\nGiven an appropriate \"param()\" call, of course. NOTE: A loop with only a single pass will\nget both \"first\" and \"last\" set to true, but not \"inner\".\n\n*   noincludes\n\nSet this option to 1 to disallow the \"<TMPLINCLUDE>\" tag in the template file. This can be\nused to make opening untrusted templates slightly less dangerous. Defaults to 0.\n\n*   maxincludes\n\nSet this variable to determine the maximum depth that includes can reach. Set to 10 by\ndefault. Including files to a depth greater than this value causes an error message to be\ndisplayed. Set to 0 to disable this protection.\n\n*   dieonmissinginclude\n\nIf true, then HTML::Template will die if it can't find a file for a \"<TMPLINCLUDE>\". This\ndefaults to true.\n\n*   globalvars\n\nNormally variables declared outside a loop are not available inside a loop. This option\nmakes \"<TMPLVAR>\"s like global variables in Perl - they have unlimited scope. This option\nalso affects \"<TMPLIF>\" and \"<TMPLUNLESS>\".\n\nExample:\n\nThis is a normal variable: <TMPLVAR NORMAL>.<P>\n\n<TMPLLOOP NAME=FROOTLOOP>\nHere it is inside the loop: <TMPLVAR NORMAL><P>\n</TMPLLOOP>\n\nNormally this wouldn't work as expected, since \"<TMPLVAR NORMAL>\"'s value outside the loop\nis not available inside the loop.\n\nThe globalvars option also allows you to access the values of an enclosing loop within an\ninner loop. For example, in this loop the inner loop will have access to the value of\n\"OUTERVAR\" in the correct iteration:\n\n<TMPLLOOP OUTERLOOP>\nOUTER: <TMPLVAR OUTERVAR>\n<TMPLLOOP INNERLOOP>\nINNER: <TMPLVAR INNERVAR>\nINSIDE OUT: <TMPLVAR OUTERVAR>\n</TMPLLOOP>\n</TMPLLOOP>\n\nOne side-effect of \"globalvars\" is that variables you set with \"param()\" that might\notherwise be ignored when \"dieonbadparams\" is off will stick around. This is necessary to\nallow inner loops to access values set for outer loops that don't directly use the value.\n\nNOTE: \"globalvars\" is not \"globalloops\" (which does not exist). That means that loops you\ndeclare at one scope are not available inside other loops even when \"globalvars\" is on.\n\n*   filter\n\nThis option allows you to specify a filter for your template files. A filter is a subroutine\nthat will be called after HTML::Template reads your template file but before it starts\nparsing template tags.\n\nIn the most simple usage, you simply assign a code reference to the filter parameter. This\nsubroutine will receive a single argument - a reference to a string containing the template\nfile text. Here is an example that accepts templates with tags that look like \"!!!ZAPVAR\nFOO!!!\" and transforms them into HTML::Template tags:\n\nmy $filter = sub {\nmy $textref = shift;\n$$textref =~ s/!!!ZAP(.*?)!!!/<TMPL$1>/g;\n};\n\n# open zap.tmpl using the above filter\nmy $template = HTML::Template->new(\nfilename => 'zap.tmpl',\nfilter   => $filter,\n);\n\nMore complicated usages are possible. You can request that your filter receives the template\ntext as an array of lines rather than as a single scalar. To do that you need to specify\nyour filter using a hash-ref. In this form you specify the filter using the \"sub\" key and\nthe desired argument format using the \"format\" key. The available formats are \"scalar\" and\n\"array\". Using the \"array\" format will incur a performance penalty but may be more\nconvenient in some situations.\n\nmy $template = HTML::Template->new(\nfilename => 'zap.tmpl',\nfilter   => {\nsub    => $filter,\nformat => 'array',\n}\n);\n\nYou may also have multiple filters. This allows simple filters to be combined for more\nelaborate functionality. To do this you specify an array of filters. The filters are applied\nin the order they are specified.\n\nmy $template = HTML::Template->new(\nfilename => 'zap.tmpl',\nfilter   => [\n{\nsub    => \\&decompress,\nformat => 'scalar',\n},\n{\nsub    => \\&removespaces,\nformat => 'array',\n},\n]\n);\n\nThe specified filters will be called for any \"TMPLINCLUDE\"ed files just as they are for the\nmain template file.\n\n*   defaultescape\n\nSet this parameter to a valid escape type (see the \"escape\" option) and HTML::Template will\napply the specified escaping to all variables unless they declare a different escape in the\ntemplate.\n\nconfig\nA package method that is used to set/get the global default configuration options. For instance,\nif you want to set the \"utf8\" flag to always be on for every template loaded by this process you\nwould do:\n\nHTML::Template->config(utf8 => 1);\n\nOr if you wanted to check if the \"utf8\" flag was on or not, you could do:\n\nmy %config = HTML::Template->config;\nif( $config{utf8} ) {\n...\n}\n\nAny configuration options that are valid for \"new()\" are acceptable to be passed to this method.\n\nparam\n\"param()\" can be called in a number of ways\n\n1 - To return a list of parameters in the template :\nmy @parameternames = $self->param();\n\n2 - To return the value set to a param :\nmy $value = $self->param('PARAM');\n\n3 - To set the value of a parameter :\n# For simple TMPLVARs:\n$self->param(PARAM => 'value');\n\n# with a subroutine reference that gets called to get the value\n# of the scalar.  The sub will receive the template object as a\n# parameter.\n$self->param(PARAM => sub { return 'value' });\n\n# And TMPLLOOPs:\n$self->param(LOOPPARAM => [{PARAM => VALUEFORFIRSTPASS}, {PARAM => VALUEFORSECONDPASS}]);\n\n4 - To set the value of a number of parameters :\n# For simple TMPLVARs:\n$self->param(\nPARAM  => 'value',\nPARAM2 => 'value'\n);\n\n# And with some TMPLLOOPs:\n$self->param(\nPARAM              => 'value',\nPARAM2             => 'value',\nLOOPPARAM         => [{PARAM => VALUEFORFIRSTPASS}, {PARAM => VALUEFORSECONDPASS}],\nANOTHERLOOPPARAM => [{PARAM => VALUEFORFIRSTPASS}, {PARAM => VALUEFORSECONDPASS}],\n);\n\n5 - To set the value of a number of parameters using a hash-ref :\n$self->param(\n{\nPARAM              => 'value',\nPARAM2             => 'value',\nLOOPPARAM         => [{PARAM => VALUEFORFIRSTPASS}, {PARAM => VALUEFORSECONDPASS}],\nANOTHERLOOPPARAM => [{PARAM => VALUEFORFIRSTPASS}, {PARAM => VALUEFORSECONDPASS}],\n}\n);\n\nAn error occurs if you try to set a value that is tainted if the \"forceuntaint\" option is\nset.\n\nclearparams\nSets all the parameters to undef. Useful internally, if nowhere else!\n\noutput\n\"output()\" returns the final result of the template. In most situations you'll want to print\nthis, like:\n\nprint $template->output();\n\nWhen output is called each occurrence of \"<TMPLVAR NAME=name>\" is replaced with the value\nassigned to \"name\" via \"param()\". If a named parameter is unset it is simply replaced with ''.\n\"<TMPLLOOP>\"s are evaluated once per parameter set, accumulating output on each pass.\n\nCalling \"output()\" is guaranteed not to change the state of the HTML::Template object, in case\nyou were wondering. This property is mostly important for the internal implementation of loops.\n\nYou may optionally supply a filehandle to print to automatically as the template is generated.\nThis may improve performance and lower memory consumption. Example:\n\n$template->output(printto => *STDOUT);\n\nThe return value is undefined when using the \"printto\" option.\n\nquery\nThis method allow you to get information about the template structure. It can be called in a\nnumber of ways. The simplest usage of query is simply to check whether a parameter name exists\nin the template, using the \"name\" option:\n\nif ($template->query(name => 'foo')) {\n# do something if a variable of any type named FOO is in the template\n}\n\nThis same usage returns the type of the parameter. The type is the same as the tag minus the\nleading 'TMPL'. So, for example, a \"TMPLVAR\" parameter returns 'VAR' from \"query()\".\n\nif ($template->query(name => 'foo') eq 'VAR') {\n# do something if FOO exists and is a TMPLVAR\n}\n\nNote that the variables associated with \"TMPLIF\"s and \"TMPLUNLESS\"s will be identified as\n'VAR' unless they are also used in a \"TMPLLOOP\", in which case they will return 'LOOP'.\n\n\"query()\" also allows you to get a list of parameters inside a loop (and inside loops inside\nloops). Example loop:\n\n<TMPLLOOP NAME=\"EXAMPLELOOP\">\n<TMPLVAR NAME=\"BEE\">\n<TMPLVAR NAME=\"BOP\">\n<TMPLLOOP NAME=\"EXAMPLEINNERLOOP\">\n<TMPLVAR NAME=\"INNERBEE\">\n<TMPLVAR NAME=\"INNERBOP\">\n</TMPLLOOP>\n</TMPLLOOP>\n\nAnd some query calls:\n\n# returns 'LOOP'\n$type = $template->query(name => 'EXAMPLELOOP');\n\n# returns ('bop', 'bee', 'exampleinnerloop')\n@paramnames = $template->query(loop => 'EXAMPLELOOP');\n\n# both return 'VAR'\n$type = $template->query(name => ['EXAMPLELOOP', 'BEE']);\n$type = $template->query(name => ['EXAMPLELOOP', 'BOP']);\n\n# and this one returns 'LOOP'\n$type = $template->query(name => ['EXAMPLELOOP', 'EXAMPLEINNERLOOP']);\n\n# and finally, this returns ('innerbee', 'innerbop')\n@innerparamnames = $template->query(loop => ['EXAMPLELOOP', 'EXAMPLEINNERLOOP']);\n\n# for non existent parameter names you get undef this returns undef.\n$type = $template->query(name => 'DWEAZLEZAPPA');\n\n# calling loop on a non-loop parameter name will cause an error. This dies:\n$type = $template->query(loop => 'DWEAZLEZAPPA');\n\nAs you can see above the \"loop\" option returns a list of parameter names and both \"name\" and\n\"loop\" take array refs in order to refer to parameters inside loops. It is an error to use\n\"loop\" with a parameter that is not a loop.\n\nNote that all the names are returned in lowercase and the types are uppercase.\n\nJust like \"param()\", \"query()\" with no arguments returns all the parameter names in the template\nat the top level.\n",
            "subsections": []
        },
        "LAZY VALUES": {
            "content": "As mentioned above, both \"TMPLVAR\" and \"TMPLLOOP\" values can be code references. These code\nreferences are only executed if the variable or loop is used in the template. This is extremely\nuseful if you want to make a variable available to template designers but it can be expensive to\ncalculate, so you only want to do so if you have to.\n\nMaybe an example will help to illustrate. Let's say you have a template like this:\n\n<tmplif wecare>\n<tmplif lifeuniverseandeverything>\n</tmplif>\n\nIf \"lifeuniverseandeverything\" is expensive to calculate we can wrap it's calculation in a\ncode reference and HTML::Template will only execute that code if \"wecare\" is also true.\n\n$tmpl->param(lifeuniverseandeverything => sub { calculate42() });\n\nYour code reference will be given a single argument, the HTML::Template object in use. In the\nabove example, if we wanted \"calculate42()\" to have this object we'd do something like this:\n\n$tmpl->param(lifeuniverseandeverything => sub { calculate42(shift) });\n\nThis same approach can be used for \"TMPLLOOP\"s too:\n\n<tmplif wecare>\n<tmplloop needlesinhaystack>\nFound <tmplvar counter>!\n</tmplloop>\n</tmplif>\n\nAnd in your Perl code:\n\n$tmpl->param(needlesinhaystack => sub { findneedles() });\n\nThe only difference in the \"TMPLLOOP\" case is that the subroutine needs to return a reference\nto an ARRAY, not just a scalar value.\n",
            "subsections": [
                {
                    "name": "Multiple Calls",
                    "content": "It's important to recognize that while this feature is designed to save processing time when\nthings aren't needed, if you're not careful it can actually increase the number of times you\nperform your calculation. HTML::Template calls your code reference each time it seems your loop\nin the template, this includes the times that you might use the loop in a conditional (\"TMPLIF\"\nor \"TMPLUNLESS\"). For instance:\n\n<tmplif we care>\n<tmplif needlesinhaystack>\n<tmplloop needlesinhaystack>\nFound <tmplvar counter>!\n</tmplloop>\n<tmplelse>\nNo needles found!\n</tmplif>\n</tmplif>\n\nThis will actually call \"findneedles()\" twice which will be even worse than you had before. One\nway to work around this is to cache the return value yourself:\n\nmy $needles;\n$tmpl->param(needlesinhaystack => sub { defined $needles ? $needles : $needles = findneedles() });\n"
                }
            ]
        },
        "BUGS": {
            "content": "I am aware of no bugs - if you find one, join the mailing list and tell us about it. You can\njoin the HTML::Template mailing-list by visiting:\n\nhttp://lists.sourceforge.net/lists/listinfo/html-template-users\n\nOf course, you can still email me directly (\"sam@tregar.com\") with bugs, but I reserve the right\nto forward bug reports to the mailing list.\n\nWhen submitting bug reports, be sure to include full details, including the VERSION of the\nmodule, a test script and a test template demonstrating the problem!\n\nIf you're feeling really adventurous, HTML::Template has a publically available Git repository.\nSee below for more information in the PUBLIC GIT REPOSITORY section.\n",
            "subsections": []
        },
        "CREDITS": {
            "content": "This module was the brain child of my boss, Jesse Erlbaum (\"jesse@vm.com\") at Vanguard Media\n(http://vm.com) . The most original idea in this module - the \"<TMPLLOOP>\" - was entirely his.\n\nFixes, Bug Reports, Optimizations and Ideas have been generously provided by:\n\n*   Richard Chen\n\n*   Mike Blazer\n\n*   Adriano Nagelschmidt Rodrigues\n\n*   Andrej Mikus\n\n*   Ilya Obshadko\n\n*   Kevin Puetz\n\n*   Steve Reppucci\n\n*   Richard Dice\n\n*   Tom Hukins\n\n*   Eric Zylberstejn\n\n*   David Glasser\n\n*   Peter Marelas\n\n*   James William Carlson\n\n*   Frank D. Cringle\n\n*   Winfried Koenig\n\n*   Matthew Wickline\n\n*   Doug Steinwand\n\n*   Drew Taylor\n\n*   Tobias Brox\n\n*   Michael Lloyd\n\n*   Simran Gambhir\n\n*   Chris Houser <chouser@bluweb.com>\n\n*   Larry Moore\n\n*   Todd Larason\n\n*   Jody Biggs\n\n*   T.J. Mather\n\n*   Martin Schroth\n\n*   Dave Wolfe\n\n*   uchum\n\n*   Kawai Takanori\n\n*   Peter Guelich\n\n*   Chris Nokleberg\n\n*   Ralph Corderoy\n\n*   William Ward\n\n*   Ade Olonoh\n\n*   Mark Stosberg\n\n*   Lance Thomas\n\n*   Roland Giersig\n\n*   Jere Julian\n\n*   Peter Leonard\n\n*   Kenny Smith\n\n*   Sean P. Scanlon\n\n*   Martin Pfeffer\n\n*   David Ferrance\n\n*   Gyepi Sam\n\n*   Darren Chamberlain\n\n*   Paul Baker\n\n*   Gabor Szabo\n\n*   Craig Manley\n\n*   Richard Fein\n\n*   The Phalanx Project\n\n*   Sven Neuhaus\n\n*   Michael Peters\n\n*   Jan Dubois\n\n*   Moritz Lenz\n\nThanks!\n",
            "subsections": []
        },
        "WEBSITE": {
            "content": "You can find information about HTML::Template and other related modules at:\n\nhttp://html-template.sourceforge.net\n",
            "subsections": []
        },
        "PUBLIC GIT REPOSITORY": {
            "content": "HTML::Template now has a publicly accessible Git repository provided by GitHub (github.com). You\ncan access it by going to https://github.com/mpeters/html-template. Give it a try!\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Sam Tregar, \"sam@tregar.com\"\n",
            "subsections": []
        },
        "CO-MAINTAINER": {
            "content": "Michael Peters, \"mpeters@plusthree.com\"\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "HTML::Template : A module for using HTML Templates with Perl\nCopyright (C) 2000-2011 Sam Tregar (sam@tregar.com)\n\nThis module is free software; you can redistribute it and/or modify it\nunder the same terms as Perl itself, which means using either:\n\na) the GNU General Public License as published by the Free Software\nFoundation; either version 1, or (at your option) any later version,\n\nor\n\nb) the \"Artistic License\" which comes with this module.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See either\nthe GNU General Public License or the Artistic License for more details.\n\nYou should have received a copy of the Artistic License with this\nmodule.  If not, I'll be glad to provide one.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n",
            "subsections": []
        }
    },
    "summary": "HTML::Template - Perl module to use HTML-like templating language",
    "flags": [],
    "examples": [],
    "see_also": []
}