AS3 Implementing a simple Templating System II

After some investigation on as3 templates engines, I write a simple class to manage key value pairs, but for a project I am now developing I have to control more things in the Template layout…

I have find a simple Javascript template System and “Ported” it to work width AS3.

It is not a “Direct Port” because I adapted it to work as a single javascript class that anyone can use from AS3.

Example Code: ( assumes classPaths are correct and have a Textfield in stage named output )

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import es.xperiments.utils.PureJSTemplate;
var exampleTemplate:XML =
<code>
<!--[CDATA[
<$=data.welcome$>
<$for(var k=0; k<data.number; k++){
    data.k = k+200;
$>
    <$=data.k$>
<$}$>
]]-->
</code>;

PureJSTemplate.addEventListener( Event.COMPLETE, onJSTemplate );
PureJSTemplate.initialize( );

function onJSTemplate( e:Event ):void
{
    PureJSTemplate.setDelimiters( "<$","$>");
    output.htmlText = PureJSTemplate.parseTemplate( "TestTemplate", exampleTemplate,{welcome:"PureJSTemplate is great",number:30} );
}

Download: Purejstemplate

Comment are closed.