Monday, April 19, 2010

haXe comes up with a simple, easy to use, proficient, efficient template system. This template system has very simple syntax to implement. HaXe has strong template library for this purpose. HaXe.template class brings all these features to us. We can create very sophisticated templates with it. This class is lightweight and well interpreted.
As we have already learnt that a template is a string or a file that we use to produce some XHTML or XML output depending on our input. Let’s see an example:
Welcome to ::name:: template system and it is ::quality::.

Here we have two template variables - ::name:: and ::quality::. We will assign different values to them.
Now we will save the above simple code into a file named: my_sample.mtt. We will use this file in our haXe code.
class Templ {
static function main() {
var str = haxe.Resource.getString("my_sample");
var t = new haxe.Template(str);
var output = t.execute({ name : "HaXe", quality : “simple and easy”});
trace(output);
}
}
We pass value to our template variable like { name : "HaXe", quality : “simple and easy”}. Now we will compile our code. First we will create an hxml file like the following:
#-swf appTemp.swf
#-neko appTemp.n
#-js appTemp.js
-resource my_sample.mtt@my_first
-main Templ
Here we have included proper command for all the platforms. Just uncomment the specific portion that is useful for a targeted platform.
This will produce an output which will have the template variables replaced by the values that we have passed to it. They will be replaced at runtime. It will show the following output:
Welcome to HaXe template system and it is simple and easy.
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide