This is an example on how to take profit from the passed resolve() function.
class Main
{
static function main()
{
var t = new haxe.Template(???I am $$yearsOld() years old???);
var out = t.execute( {
birthYear : 1972
}, {
yearsOld : function( resolve : String - > Dynamic) {
// a little bit approximative
return Date.now().getFullYear() - resolve(???birthYear???);
}
});
trace(out);
}
}
The resolve function works in the current template context to look for a suitable value.
Using Resources
Until now, all the template contents have been written inline in the code context. This is not really a good
practice but it is useful when templates are used in a test phase or if they are very short. The ideal way to
deal with the content of a template is to put it in a resource file, which will be embedded in the result file
at compilation time.
A template resource is no more than a plain text file. A file page.tpl has been created with the
following content:
< html >
< head >
< title > ::title:: < /title >
< /head >
< body >
::content::
< /body >
< /html >
Part II: Server Side, JavaScript, and Flash; Oh My!
258
Now it is necessary to say to the compiler that this resource must be embedded in the output.
Pages:
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505