The test process listing again
Before looking at the core template files that implement the token system, take one last look at the test process. Below is the pseudo-code listing again with a couple of lines added. These lines added immediately before and after the creation and use of the TemplateHTML class will add and then remove a value from the global properties array called 'VAR.temp'. Variables in the global properties array prepended with 'VAR.' are known as temporary variables. Here is the listing:
{
array props = new array();
Form.parse(...);
Config.parse( "../config/php.config", props );
Config.parse( "../config/global.config", props );
contenttype( "text/html" );
props{ "VAR.temp" } = "This is a temporary variable!";
TemplateHTML template = new TemplateHTML();
print( template.process_file( props{ "CONFIG.rootDir" } +
"template/" +
"test" +
".html", props ) );
delete( props{ "VAR.temp" } );
}
Just like the form and configuration variables, temporary variables are echoed automatically by Jasper. Unlike the form and configuration variables, however, Jasper does not create any temporary variables of itself. Jasper will look for values in the global properties array starting with 'VAR.' and echo them but nothing else. Try adding the following line to the 'test.html' template file to confirm the temporary variable does indeed get echoed:
<p> The value of the 'temp' temporary variable is: <strong>'[[temp]]'</strong> </p>
The functionality is there for you to use and abuse as you see fit. Use of temporary variables consists of setting them before processing the template file that references them and then explicitly deleting them. Abuse consists of failing to delete them once used. This is strongly discouraged.
The concrete language equivalents of the delete(...) method given in the pseudo-code listing above are given here for your encouragement and you should use them religiously:
// Java
props.remove( "VAR.test" );
// C#
props.Remove( "VAR.test" );
# PHP
unset( $props{ "VAR.test" } );
# Perl
delete( $props->{ "VAR.test" } );
Parsing of temporary variables alongside form and configuration files completes the functionality that Jasper implements for processing HTML template files. By default it does no more. The remainder of this tutorial shows how this parsing is done.
Last updated: Sunday, 23rd October 2011, 06:48 PM
User comments:
There are none.