back to tpl 

tpl.Engine

generated from ../src/mod_tpl/tpl.cpp

A class used for generating output using templates (based on LibTemplate). Template variables are dynamic properties. This means that adding a property to this class, adds a template variable. The following is an example on using this class:


   var engine = new tpl.Engine();
   var n = 1;

   // Load the template file
   engine.load("test.tpl");
   for(n = 1;n <= 10; n++) 
   {
     engine.base   = n;
     engine.square = n * n;
     engine.cube   = n * n * n;
     // Parse the template 'row' and add the result to element 'rows'
     engine.parse("row", "rows", true);
   }

   engine.parse("grid", "main", false);
   var output = engine.main;
   
The template file 'test.tpl' looks like this:
   <template name="grid">
      Base	Square	Cube
      ----	------	----
      {rows}
      ----------------------------
      
      The quotes "{empty}" should be empty.
   </template>

   <template name="row">
    {base}	{square}	{cube}
   </template> 
  
Use this class to separate the HTML code (View) from the JavaScript code (Model and Controller). Remark:It's not allowed to put text before or after a template-tag on the same line!.

Constants

Constructor

Engine

Engine(Path = "")
 
Name Type Default Description
Path String The path to start for searching templates. The default is the path of the currently executing script

Constructs a new TemplateEngine

Methods

load

load(Filename, 
     Encoding = UTF-8)
 
Name Type Default Description
Filename String Name of the template file
Encoding String UTF-8 Encoding of the file

Loads a template file and appends the templates to the engine.

parse

parse(name, 
      newname, 
      append = true) : boolean
 
Name Type Default Description
name String Template name to compile
newname String Element name to store the result in
append Boolean true false - replace the existing value, if any true - append to the existing value, if any

Substitute the element values for their tags in the compiled template.



SourceForge.net Logo Support This Project

Table of Contents

Constructor

Engine

Methods

load
parse


Design downloaded from Zeroweb.org: Free website templates, layouts, and tools.