{
    "content": [
        {
            "type": "text",
            "text": "# Template (man)\n\n## NAME\n\nTemplate - Front-end module to the Template Toolkit\n\n## SYNOPSIS\n\nuse Template;\n# some useful options (see below for full list)\nmy $config = {\nINCLUDEPATH => '/search/path',  # or list ref\nINTERPOLATE  => 1,               # expand \"$var\" in plain text\nPOSTCHOMP   => 1,               # cleanup whitespace\nPREPROCESS  => 'header',        # prefix each template\nEVALPERL    => 1,               # evaluate Perl code blocks\n};\n# create Template object\nmy $template = Template->new($config);\n# define template variables for replacement\nmy $vars = {\nvar1  => $value,\nvar2  => \\%hash,\nvar3  => \\@list,\nvar4  => \\&code,\nvar5  => $object,\n};\n# specify input filename, or file handle, text reference, etc.\nmy $input = 'myfile.html';\n# process input template, substituting variables\n$template->process($input, $vars)\n|| die $template->error();\n\n## DESCRIPTION\n\nThis documentation describes the Template module which is the direct Perl interface into the\nTemplate Toolkit.  It covers the use of the module and gives a brief summary of configuration\noptions and template directives.  Please see Template::Manual for the complete reference\nmanual which goes into much greater depth about the features and use of the Template Toolkit.\nThe Template::Tutorial is also available as an introductory guide to using the Template\nToolkit.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **METHODS**\n- **CONFIGURATION SUMMARY**\n- **DIRECTIVE SUMMARY**\n- **SOURCE CODE REPOSITORY**\n- **AUTHOR**\n- **VERSION**\n- **COPYRIGHT**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Template",
        "section": "",
        "mode": "man",
        "summary": "Template - Front-end module to the Template Toolkit",
        "synopsis": "use Template;\n# some useful options (see below for full list)\nmy $config = {\nINCLUDEPATH => '/search/path',  # or list ref\nINTERPOLATE  => 1,               # expand \"$var\" in plain text\nPOSTCHOMP   => 1,               # cleanup whitespace\nPREPROCESS  => 'header',        # prefix each template\nEVALPERL    => 1,               # evaluate Perl code blocks\n};\n# create Template object\nmy $template = Template->new($config);\n# define template variables for replacement\nmy $vars = {\nvar1  => $value,\nvar2  => \\%hash,\nvar3  => \\@list,\nvar4  => \\&code,\nvar5  => $object,\n};\n# specify input filename, or file handle, text reference, etc.\nmy $input = 'myfile.html';\n# process input template, substituting variables\n$template->process($input, $vars)\n|| die $template->error();",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 30,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 7,
                "subsections": []
            },
            {
                "name": "METHODS",
                "lines": 183,
                "subsections": []
            },
            {
                "name": "CONFIGURATION SUMMARY",
                "lines": 170,
                "subsections": []
            },
            {
                "name": "DIRECTIVE SUMMARY",
                "lines": 221,
                "subsections": []
            },
            {
                "name": "SOURCE CODE REPOSITORY",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "VERSION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "COPYRIGHT",
                "lines": 6,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Template - Front-end module to the Template Toolkit\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use Template;\n\n# some useful options (see below for full list)\nmy $config = {\nINCLUDEPATH => '/search/path',  # or list ref\nINTERPOLATE  => 1,               # expand \"$var\" in plain text\nPOSTCHOMP   => 1,               # cleanup whitespace\nPREPROCESS  => 'header',        # prefix each template\nEVALPERL    => 1,               # evaluate Perl code blocks\n};\n\n# create Template object\nmy $template = Template->new($config);\n\n# define template variables for replacement\nmy $vars = {\nvar1  => $value,\nvar2  => \\%hash,\nvar3  => \\@list,\nvar4  => \\&code,\nvar5  => $object,\n};\n\n# specify input filename, or file handle, text reference, etc.\nmy $input = 'myfile.html';\n\n# process input template, substituting variables\n$template->process($input, $vars)\n|| die $template->error();\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This documentation describes the Template module which is the direct Perl interface into the\nTemplate Toolkit.  It covers the use of the module and gives a brief summary of configuration\noptions and template directives.  Please see Template::Manual for the complete reference\nmanual which goes into much greater depth about the features and use of the Template Toolkit.\nThe Template::Tutorial is also available as an introductory guide to using the Template\nToolkit.\n",
                "subsections": []
            },
            "METHODS": {
                "content": "new(\\%config)\nThe \"new()\" constructor method (implemented by the Template::Base base class) instantiates a\nnew \"Template\" object. A reference to a hash array of configuration items may be passed as a\nparameter.\n\nmy $tt = Template->new({\nINCLUDEPATH => '/usr/local/templates',\nEVALPERL    => 1,\n}) || die $Template::ERROR, \"\\n\";\n\nA reference to a new \"Template\" object is returned, or undef on error. In the latter case,\nthe error message can be retrieved by calling error() as a class method or by examining the\n$Template::ERROR package variable directly.\n\nmy $tt = Template->new(\\%config)\n|| die Template->error(), \"\\n\";\n\nmy $tt = Template->new(\\%config)\n|| die $Template::ERROR, \"\\n\";\n\nFor convenience, configuration items may also be specified as a list of items instead of a\nhash array reference.  These are automatically folded into a hash array by the constructor.\n\nmy $tt = Template->new(INCLUDEPATH => '/tmp', POSTCHOMP => 1)\n|| die $Template::ERROR, \"\\n\";\n\nprocess($template, \\%vars, $output, %options)\nThe \"process()\" method is called to process a template. The first parameter indicates the\ninput template as one of: a filename relative to \"INCLUDEPATH\", if defined; a reference to a\ntext string containing the template text; or a file handle reference (e.g. \"IO::Handle\" or\nsub-class) or \"GLOB\" (e.g. \"\\*STDIN\"), from which the template can be read. A reference to a\nhash array may be passed as the second parameter, containing definitions of template\nvariables.\n\n# filename\n$tt->process('welcome.tt2')\n|| die $tt->error(), \"\\n\";\n\n# text reference\n$text = \"[% INCLUDE header %]\\nHello world!\\n[% INCLUDE footer %]\";\n$tt->process(\\$text)\n|| die $tt->error(), \"\\n\";\n\n# file handle (GLOB)\n$tt->process(\\*DATA)\n|| die $tt->error(), \"\\n\";\n\nEND\n[% INCLUDE header %]\nThis is a template defined in the END section which is\naccessible via the DATA \"file handle\".\n[% INCLUDE footer %]\n\nBy default, the processed template output is printed to \"STDOUT\". The \"process()\" method then\nreturns 1 to indicate success. A third parameter may be passed to the \"process()\" method to\nspecify a different output location.  This value may be one of: a plain string indicating a\nfilename which will be opened (relative to \"OUTPUTPATH\", if defined) and the output written\nto; a file GLOB opened ready for output; a reference to a scalar (e.g. a text string) to\nwhich output/error is appended; a reference to a subroutine which is called, passing the\noutput as a parameter; or any object reference which implements a \"print()\" method (e.g.\n\"IO::Handle\", \"Apache::Request\", etc.) which will be called, passing the generated output as\na parameter.\n\nExamples:\n\n# output filename\n$tt->process('welcome.tt2', $vars, 'welcome.html')\n|| die $tt->error(), \"\\n\";\n\n# reference to output subroutine\nsub myout {\nmy $output = shift;\n...\n}\n$tt->process('welcome.tt2', $vars, \\&myout)\n|| die $tt->error(), \"\\n\";\n\n# reference to output text string\nmy $output = '';\n$tt->process('welcome.tt2', $vars, \\$output)\n|| die $tt->error(), \"\\n\";\n\nprint \"output: $output\\n\";\n\nIn an Apache/modperl handler:\n\nsub handler {\nmy $req = shift;\n\n# ...your code here...\n\n# direct output to Apache::Request via $req->print($output)\n$tt->process($file, $vars, $req) || do {\n$req->logreason($tt->error());\nreturn SERVERERROR;\n};\nreturn OK;\n}\n\nAfter the optional third output argument can come an optional reference to a hash or a list\nof \"(name, value)\" pairs providing further options for the output.  The only option currently\nsupported is \"binmode\" which, when set to any true value will ensure that files created (but\nnot any existing file handles passed) will be set to binary mode.\n\n# either: hash reference of options\n$tt->process($infile, $vars, $outfile, { binmode => 1 })\n|| die $tt->error(), \"\\n\";\n\n# or: list of name, value pairs\n$tt->process($infile, $vars, $outfile, binmode => 1)\n|| die $tt->error(), \"\\n\";\n\nAlternately, the \"binmode\" argument can specify a particular IO layer such as \":utf8\".\n\n$tt->process($infile, $vars, $outfile, binmode => ':utf8')\n|| die $tt->error(), \"\\n\";\n\nThe \"OUTPUT\" configuration item can be used to specify a default output location other than\n\"\\*STDOUT\".  The \"OUTPUTPATH\" specifies a directory which should be prefixed to all output\nlocations specified as filenames.\n\nmy $tt = Template->new({\nOUTPUT      => sub { ... },       # default\nOUTPUTPATH => '/tmp',\n...\n}) || die Template->error(), \"\\n\";\n\n# use default OUTPUT (sub is called)\n$tt->process('welcome.tt2', $vars)\n|| die $tt->error(), \"\\n\";\n\n# write file to '/tmp/welcome.html'\n$tt->process('welcome.tt2', $vars, 'welcome.html')\n|| die $tt->error(), \"\\n\";\n\nThe \"process()\" method returns 1 on success or \"undef\" on error. The error message generated\nin the latter case can be retrieved by calling the error() method. See also \"CONFIGURATION\nSUMMARY\" which describes how error handling may be further customised.\n\nerror()\nWhen called as a class method, it returns the value of the $ERROR package variable.  Thus,\nthe following are equivalent.\n\nmy $tt = Template->new()\n|| die Template->error(), \"\\n\";\n\nmy $tt = Template->new()\n|| die $Template::ERROR, \"\\n\";\n\nWhen called as an object method, it returns the value of the internal \"ERROR\" variable, as\nset by an error condition in a previous call to process().\n\n$tt->process('welcome.tt2')\n|| die $tt->error(), \"\\n\";\n\nErrors are represented in the Template Toolkit by objects of the Template::Exception class.\nIf the process() method returns a false value then the \"error()\" method can be called to\nreturn an object of this class.  The type() and info() methods can called on the object to\nretrieve the error type and information string, respectively. The asstring() method can be\ncalled to return a string of the form \"$type - $info\". This method is also overloaded onto\nthe stringification operator allowing the object reference itself to be printed to return the\nformatted error string.\n\n$tt->process('somefile') || do {\nmy $error = $tt->error();\nprint \"error type: \", $error->type(), \"\\n\";\nprint \"error info: \", $error->info(), \"\\n\";\nprint $error, \"\\n\";\n};\n\nservice()\nThe \"Template\" module delegates most of the effort of processing templates to an underlying\nTemplate::Service object.  This method returns a reference to that object.\n\ncontext()\nThe Template::Service module uses a core Template::Context object for runtime processing of\ntemplates.  This method returns a reference to that object and is equivalent to\n\"$template->service->context()\".\n\ntemplate($name)\nThis method is a simple wrapper around the Template::Context method of the same name.  It\nreturns a compiled template for the source provided as an argument.\n",
                "subsections": []
            },
            "CONFIGURATION SUMMARY": {
                "content": "The following list gives a short summary of each Template Toolkit configuration option.  See\nTemplate::Manual::Config for full details.\n\nTemplate Style and Parsing Options\nENCODING\n\nSpecifies the character encoding.\n\nSTARTTAG, ENDTAG\n\nDefine tokens that indicate start and end of directives (default: '\"[%\"' and '\"%]\"').\n\nTAGSTYLE\n\nSet \"STARTTAG\" and \"ENDTAG\" according to a pre-defined style (default: '\"template\"', as\nabove).\n\nPRECHOMP, POSTCHOMP\n\nRemoves whitespace before/after directives (default: 0/0).\n\nTRIM\n\nRemove leading and trailing whitespace from template output (default: 0).\n\nINTERPOLATE\n\nInterpolate variables embedded like $this or \"${this}\" (default: 0).\n\nANYCASE\n\nAllow directive keywords in lower case (default: 0 - UPPER only).\n\nTemplate Files and Blocks\nINCLUDEPATH\n\nOne or more directories to search for templates.\n\nDELIMITER\n\nDelimiter for separating paths in \"INCLUDEPATH\" (default: '\":\"').\n\nABSOLUTE\n\nAllow absolute file names, e.g. \"/foo/bar.html\" (default: 0).\n\nRELATIVE\n\nAllow relative filenames, e.g. \"../foo/bar.html\" (default: 0).\n\nDEFAULT\n\nDefault template to use when another not found.\n\nBLOCKS\n\nHash array pre-defining template blocks.\n\nAUTORESET\n\nEnabled by default causing \"BLOCK\" definitions to be reset each time a template is processed.\nDisable to allow \"BLOCK\" definitions to persist.\n\nRECURSION\n\nFlag to permit recursion into templates (default: 0).\n\nTemplate Variables\nVARIABLES\n\nHash array of variables and values to pre-define in the stash.\n\nRuntime Processing Options\nEVALPERL\n\nFlag to indicate if \"PERL\"/\"RAWPERL\" blocks should be processed (default: 0).\n\nPREPROCESS, POSTPROCESS\n\nName of template(s) to process before/after main template.\n\nPROCESS\n\nName of template(s) to process instead of main template.\n\nERROR\n\nName of error template or reference to hash array mapping error types to templates.\n\nOUTPUT\n\nDefault output location or handler.\n\nOUTPUTPATH\n\nDirectory into which output files can be written.\n\nDEBUG\n\nEnable debugging messages.\n\nCaching and Compiling Options\nCACHESIZE\n\nMaximum number of compiled templates to cache in memory (default: undef - cache all)\n\nCOMPILEEXT\n\nFilename extension for compiled template files (default: undef - don't compile).\n\nCOMPILEDIR\n\nRoot of directory in which compiled template files should be written (default: undef - don't\ncompile).\n\nPlugins and Filters\nPLUGINS\n\nReference to a hash array mapping plugin names to Perl packages.\n\nPLUGINBASE\n\nOne or more base classes under which plugins may be found.\n\nLOADPERL\n\nFlag to indicate regular Perl modules should be loaded if a named plugin can't be found\n(default: 0).\n\nFILTERS\n\nHash array mapping filter names to filter subroutines or factories.\n\nCustomisation and Extension\nLOADTEMPLATES\n\nList of template providers.\n\nLOADPLUGINS\n\nList of plugin providers.\n\nLOADFILTERS\n\nList of filter providers.\n\nTOLERANT\n\nSet providers to tolerate errors as declinations (default: 0).\n\nSERVICE\n\nReference to a custom service object (default: Template::Service).\n\nCONTEXT\n\nReference to a custom context object (default: Template::Context).\n\nSTASH\n\nReference to a custom stash object (default: Template::Stash).\n\nPARSER\n\nReference to a custom parser object (default: Template::Parser).\n\nGRAMMAR\n\nReference to a custom grammar object (default: Template::Grammar).\n",
                "subsections": []
            },
            "DIRECTIVE SUMMARY": {
                "content": "The following list gives a short summary of each Template Toolkit directive.  See\nTemplate::Manual::Directives for full details.\n\nGET\nEvaluate and print a variable or value.\n\n[%   GET variable %]    # 'GET' keyword is optional\n[%       variable %]\n[%       hash.key %]\n[%         list.n %]\n[%     code(args) %]\n[% obj.meth(args) %]\n[%  \"value: $var\" %]\n\nCALL\nAs per GET but without printing result (e.g. call code)\n\n[%  CALL variable %]\n\nSET\nAssign a values to variables.\n\n[% SET variable = value %]    # 'SET' also optional\n[%     variable = othervariable\nvariable = 'literal text @ $100'\nvariable = \"interpolated text: $var\"\nlist     = [ val, val, val, val, ... ]\nlist     = [ val..val ]\nhash     = { var => val, var => val, ... }\n%]\n\nDEFAULT\nLike SET, but variables are only set if currently unset (i.e. have no true value).\n\n[% DEFAULT variable = value %]\n\nINSERT\nInsert a file without any processing performed on the contents.\n\n[% INSERT legalese.txt %]\n\nPROCESS\nProcess another template file or block and insert the generated output.  Any template BLOCKs\nor variables defined or updated in the \"PROCESS\"ed template will thereafter be defined in the\ncalling template.\n\n[% PROCESS template %]\n[% PROCESS template  var = val, ... %]\n\nINCLUDE\nSimilar to \"PROCESS\", but using a local copy of the current variables.  Any template \"BLOCK\"s\nor variables defined in the \"INCLUDE\"d template remain local to it.\n\n[% INCLUDE template %]\n[% INCLUDE template  var = val, ... %]\n\nWRAPPER\nThe content between the \"WRAPPER\" and corresponding \"END\" directives is first evaluated, with\nthe output generated being stored in the \"content\" variable.  The named template is then\nprocess as per \"INCLUDE\".\n\n[% WRAPPER layout %]\nSome template markup [% blah %]...\n[% END %]\n\nA simple layout template might look something like this:\n\nYour header here...\n[% content %]\nYour footer here...\n\nBLOCK\nDefine a named template block for INCLUDE, PROCESS and WRAPPER to use.\n\n[% BLOCK hello %]\nHello World\n[% END %]\n\n[% INCLUDE hello %]\n\nFOREACH\nRepeat the enclosed \"FOREACH\" ... \"END\" block for each value in the list.\n\n[% FOREACH variable IN [ val, val, val ] %]    # either\n[% FOREACH variable IN list %]                 # or\nThe variable is set to [% variable %]\n[% END %]\n\nWHILE\nThe block enclosed between \"WHILE\" and \"END\" block is processed while the specified condition\nis true.\n\n[% WHILE condition %]\ncontent\n[% END %]\n\nIF / UNLESS / ELSIF / ELSE\nThe enclosed block is processed if the condition is true / false.\n\n[% IF condition %]\ncontent\n[% ELSIF condition %]\ncontent\n[% ELSE %]\ncontent\n[% END %]\n\n[% UNLESS condition %]\ncontent\n[% # ELSIF/ELSE as per IF, above %]\ncontent\n[% END %]\n\nSWITCH / CASE\nMulti-way switch/case statement.\n\n[% SWITCH variable %]\n[%   CASE val1 %]\ncontent\n[%   CASE [ val2, val3 ] %]\ncontent\n[%   CASE %]         # or [% CASE DEFAULT %]\ncontent\n[% END %]\n\nMACRO\nDefine a named macro.\n\n[% MACRO name <directive> %]\n[% MACRO name(arg1, arg2) <directive> %]\n...\n[% name %]\n[% name(val1, val2) %]\n\nFILTER\nProcess enclosed \"FILTER\" ... \"END\" block then pipe through a filter.\n\n[% FILTER name %]                       # either\n[% FILTER name( params ) %]             # or\n[% FILTER alias = name( params ) %]     # or\ncontent\n[% END %]\n\nUSE\nLoad a plugin module (see \"Template::<Manual::Plugins\"), or any regular Perl module when the\n\"LOADPERL\" option is set.\n\n[% USE name %]                      # either\n[% USE name( params ) %]            # or\n[% USE var = name( params ) %]      # or\n...\n[% name.method %]\n[% var.method %]\n\nPERL / RAWPERL\nEvaluate enclosed blocks as Perl code (requires the \"EVALPERL\" option to be set).\n\n[% PERL %]\n# perl code goes here\n$stash->set('foo', 10);\nprint \"set 'foo' to \", $stash->get('foo'), \"\\n\";\nprint $context->include('footer', { var => $val });\n[% END %]\n\n[% RAWPERL %]\n# raw perl code goes here, no magic but fast.\n$output .= 'some output';\n[% END %]\n\nTRY / THROW / CATCH / FINAL\nException handling.\n\n[% TRY %]\ncontent\n[% THROW type info %]\n[% CATCH type %]\ncatch content\n[% error.type %] [% error.info %]\n[% CATCH %] # or [% CATCH DEFAULT %]\ncontent\n[% FINAL %]\nthis block is always processed\n[% END %]\n\nNEXT\nJump straight to the next item in a \"FOREACH\" or \"WHILE\" loop.\n\n[% NEXT %]\n\nLAST\nBreak out of \"FOREACH\" or \"WHILE\" loop.\n\n[% LAST %]\n\nRETURN\nStop processing current template and return to including templates.\n\n[% RETURN %]\n\nSTOP\nStop processing all templates and return to caller.\n\n[% STOP %]\n\nTAGS\nDefine new tag style or characters (default: \"[%\" \"%]\").\n\n[% TAGS html %]\n[% TAGS <!-- --> %]\n\nCOMMENTS\nIgnored and deleted.\n\n[% # this is a comment to the end of line\nfoo = 'bar'\n%]\n\n[%# placing the '#' immediately inside the directive\ntag comments out the entire directive\n%]\n",
                "subsections": []
            },
            "SOURCE CODE REPOSITORY": {
                "content": "The source code for the Template Toolkit is held in a public git repository on Github:\n<https://github.com/abw/Template2>\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Andy Wardley <abw@wardley.org> <http://wardley.org/>\n",
                "subsections": []
            },
            "VERSION": {
                "content": "Template Toolkit version 2.26, released January 2014.\n",
                "subsections": []
            },
            "COPYRIGHT": {
                "content": "Copyright (C) 1996-2014 Andy Wardley.  All Rights Reserved.\n\nThis module is free software; you can redistribute it and/or modify it under the same terms\nas Perl itself.\n\nperl v5.34.0                                2026-05-30                              Template(3pm)",
                "subsections": []
            }
        }
    }
}