Monday, April 19, 2010

Template system in haXe

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




List of my works:

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

No comments: