The evaltt filter is provided as an alias for eval. The perl filter evaluates the block as Perl code.
Thus, the previous example could have been written in the more verbose form:. The evalperl filter is provided as an alias for perl for backwards compatibility.
The binmode option can be passed as either a named parameter or a single argument to set STDOUT to binary mode see the binmode perl function. See the null filter below for an example. The null filter prints nothing. This is useful for plugins whose methods return values that you don't want to appear in the output. Rather than assigning every plugin method call to a dummy variable to silence it, you can wrap the block in a null filter:.
Notice the use of the stdout filter to ensure that a particular expression generates output to STDOUT in this case in binary mode. It's very nice. Click to hide the menu and go all widescreen! Contents Top Close Open. Folds the input to lower case. Folds the first character of the input to lower case. Mary had a little lamb. Output: We want more beer and we want more beer, We want more beer and we want more beer, We want more beer and we want more beer, We are the more beer wanters!
The header and footer template files have been included assuming you created them and they're in the current directory and the link data has been built into an HTML list. The tpage script gives you a simple and easy way to process a single template without having to write any Perl code.
The ttree:Template::Tools::ttree script, also distributed as part of the Template Toolkit, provides a more flexible way to process a number of template documents in one go. The first time you run the script, it will ask you if it should create a configuration file. Answer y to have it create the file. The ttree:Template::Tools::ttree documentation describes how you can change the location of this file and also explains the syntax and meaning of the various options in the file.
Comments are written to the sample configuration file which should also help. In brief, the configuration file describes the directories in which template files are to be found src , where the corresponding output should be written to dest , and any other directories lib that may contain template files that you plan to INCLUDE into your source documents.
You can create many different configuration files and store them in the directory specified in the cfg option, shown above. You then add the -f filename option to ttree to have it read that file. When you run the script, it compares all the files in the src directory including those in sub-directories if the recurse option is set , with those in the dest directory. If the destination file doesn't exist or has an earlier modification time than the corresponding source file, then the source will be processed with the output written to the destination file.
The -a option forces all files to be processed, regardless of modification times. Thus, the lib directory is an excellent place to keep template elements such as header, footers, etc. You can also specify various Template Toolkit options from the configuration file.
Consult the ttree documentation and help summary ttree -h for full details. In the fragment above, we have specified that the config template should be used as a prefix template. We can create this file in the lib directory and use it to define some common variables, including those web page links we defined earlier and might want to re-use in other templates.
We could also include an HTML header, title, or menu bar in this file which would then be prepended to each and every template file, but for now we'll keep all that in a separate header file. Assuming you've created or copied the header and footer files from the earlier example into your lib directory, you can now start to create web pages like the following in your src directory and process them with ttree.
Here we've shown how pre-defined variables can be used as flags to enable certain feature e. This approach allows you to define these values once so that they're consistent across all pages and can easily be changed to new values. When you run ttree , you should see output similar to the following assuming you have the verbose flag set.
If you run the same command again, you'll see the following line displayed instead showing a - and giving a reason why the file wasn't processed. It has detected a newpage. To force all files to be processed, use the -a option. You can also specify one or more filenames as command line arguments to ttree :. You can add as many documents as you like to the src directory and ttree will apply the same process to them all.
In this way, it is possible to build an entire tree of static content for a web site with a single command. The added benefit is that you can be assured of consistency in links, header style, or whatever else you choose to implement in terms of common templates elements or variables.
Simply use the Template module, create an object instance with the new method and then call the process method on the object, passing the name of the template file as a parameter. The second parameter passed is a reference to a hash array of variables that we want made available to the template:.
So that our scripts will work with the same template files as our earlier examples, we'll can add some configuration options to the constructor to tell it about our environment:. This means that the templates we process can use the same global variables defined earlier for our static pages. We don't have to replicate their definitions in this script.
However, we can supply additional data and functionality specific to this script via the hash of variables that we pass to the process method.
Setting this option will automatically enable outline tags. You can also use the TAGS directive to define your own custom tags start, end and now optionally, outline for a template or part of a template. If you only specify a start and end tag then outline tags will be disabled.
The character is used to indicate comments within a directive. When placed immediately inside the opening directive tag, it causes the entire directive to be ignored. In any other position, it causes the remainder of the current line to be treated as a comment. The GET and SET keywords are actually optional as the parser is smart enough to see them for what they really are but note the caveat below on using side-effect notation.
Thus, you'll generally see:. You can also express simple logical statements as implicit GET directives:. It is perfectly valid, for example, to define a variable called stop which is entirely separate from the STOP directive. Blocks may be nested indefinitely. The output of a directive can be captured by simply assigning the directive to a variable. This can be used in conjunction with the BLOCK directive for defining large blocks of text or other content.
Note one important caveat of using this syntax in conjunction with side-effect notation.
0コメント