Prev | Current Page 491 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

Template(???the content is: ::content::???);
var content = contentTpl.execute({ content : ???content goes here??? });
var containerTpl = new haxe.Template(??? < h1 > ::title:: < /h1 > ::content::???);
var out = containerTpl.execute({ title : ???My Page??? , content : content });
trace(out);
}
}
Using Macros
Sometimes you will feel the need to apply more complex transformations to your data before sending
them to the screen. Of course, this is the case of transformations needed just for presentation purposes;
otherwise, it will be more appropriate to write that code in the business logic of your application.
Macros are just function references or callbacks to your haXe code. Therefore, to have a function you
have written in haXe available in a template, you must pass an explicit reference to it using macros. Not
having all the functions defined available in the template is a choice of performance and security.
The base syntax to call a macro inside a template is the following:
class Main
{
static function main()
{
var t = new haxe.


Pages:
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503