Prev | Current Page 485 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

This object may be anonymous or a
class instance.
class Main
{
static function main()
{
var t = new haxe.Template(???Hello ::name::!???);
var out = t.execute({ name : ???John Doe??? });
trace(out);
}
}
The result is:
Main.hx:7: Hello John Doe!
Note how the placeholder ::name:: has been replaced by the content of the corresponding field of the
data object. The execute method, also accepts an optional extra argument for macro definitions; the use
of this argument is discussed in the ??? Using Macros ??? section.
Table 10 - 1
Template Class Method Description
new (str:String) : Void The constructor accepts one argument, which is the content of
the template.
execute(context:Dynamic,
?macros:Dynamic) : String
The first mandatory parameter is an object containing
the values that must be used in substitution for the
placeholders. The second optional parameter is an object
containing macros references.
Chapter 10: Separating Design Using Templates
253
The Template Syntax
Placeholders are blocks of characters in a template that are marked with the :: prefix and suffix.


Pages:
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497