To do that,
the following switch is added to the compilation command or to the .hxml file if one is used:
-resource page.tpl@webpage
The filename of the resource file is followed by the @ symbol, followed by the name that is used in the
code to reference the resource.
Finally, the resource is used in code just using the following syntax:
var t = new haxe.Template(Std.resource(???webpage???));
This way the template content is easily separated from the code that makes use of it.
When to Use Code in Templates?
Templates seen so far are very useful in many situations but they have quite an important drawback:
They are parsed and interpreted on each call. That is usually not important when the template
replacement occurs on the client side (Flash and JavaScript) or the size is not that big, but may be more
than an issue if the templates are elaborated on the server side and quite complex and the server has to
manage many requests at the same time. In that case a very simple solution is to switch to Templo of the
Motion - Twin library, which has a similar syntax but uses compiled templates instead of interpreted ones,
which obviously have a very different level of performances.
Pages:
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506