Please see Template::Manual for the complete reference manual which goes into much greater depth about the features and use of the Template Toolkit. The Template::Tutorial is also available as an introductory guide to using the Template Toolkit. The new constructor method implemented by the Template::Base base class instantiates a new Template object. A reference to a hash array of configuration items may be passed as a parameter.
A reference to a new Template object is returned, or undef on error. For convenience, configuration items may also be specified as a list of items instead of a hash array reference. These are automatically folded into a hash array by the constructor.
The process method is called to process a template. The first parameter indicates the input template as one of:. A reference to a hash array may be passed as the second parameter, containing definitions of template variables. The process method then returns 1 to indicate success. A third parameter may be passed to the process method to specify a different output location. This value may be one of:. IO::Handle , Apache::Request , etc. After the optional third output argument can come an optional reference to a hash or a list of name, value pairs providing further options for the output.
The only option currently supported is binmode which, when set to any true value will ensure that files created but not any existing file handles passed will be set to binary mode. Alternately, the binmode argument can specify a particular IO layer such as :utf8. The process method returns 1 on success or undef on error. The error message generated in the latter case can be retrieved by calling the error method. See below for details. NOTE : Storable uses flock to ensure safe access to cache files.
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.
Defaults to "" for security but this may be inconvenient if you do not have access to the account running the webserver. This list is only consulted when the filename is relative. The normal behavior is to look only in the current directory for a template to include. This will apply to any file's passed to new or any included files. It won't do anything special to scalars templates passed to new since you should be doing the encoding on those yourself.
See PerlIO for details. NOTE : you have to supply an opening mode that actually permits reading from the file handle. Requires the GTop module. 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 query object. 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:. NOTE : The parameter names are matched in a case-insensitive manner. When this parameter is set to true it is false by default extra variables that depend on the loop's context are made available inside a loop.
These are:. One use of this feature is to provide a "separator" similar in effect to the perl function join. Given an appropriate param call, of course. This can be used to make opening untrusted templates slightly less dangerous. 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. This defaults to true.
Normally variables declared outside a loop are not available inside a loop. This is necessary to allow inner loops to access values set for outer loops that don't directly use the value. 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 receive a single argument - a reference to a string containing the template file text. Here is an example that accepts templates with tags that look like!!!
More complicated usages are possible. You can request that your filter receives 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.
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. Set this parameter to a valid escape type see the escape option and HTML::Template will apply the specified escaping to all variables unless they declare a different escape in the template.
For instance, if you want to set the utf8 flag to always be on for every template loaded by this process you would do:. Any configuration options that are valid for new are acceptable to be passed to this method. In most situations you'll want to print this, like:. If a named parameter is unset it is simply replaced with ''. Calling output is guaranteed not to change the state of the HTML::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. Note that not all Perl modules have been packaged for ppm.
You can find a list of additional repositories by installing the PPM::Repositories module, then running this code:. Failing all else, you could install the module by hand. Then, simply replace make with nmake in the instructions above. While the majority of modules are pure Perl, some may contain C code, in which case you will need a C compiler.
A compiler is never required for ppm packages. Some modules are dependent on other modules, which in turn may have other dependencies. Installing all these modules can be a bit tedious, but there is an alternative: install the CPAN package. Then, simply invoke the cpan shell from the command line:. The first time cpan is run, it will configure itself.
Answer the prompts, and when the configuration is complete, you can install your package:. Maintaining and extending such an application can become quite onerous. Most Web languages provide some means to separate the application code from the markup code.
In most cases, the HTML is placed in separate template files, which then act as containers for dynamic data.
0コメント