Skip to content
php-alike, double pass templates, 1) onload , 2) onuse , used in nodejs-mongodb-app see it as example
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Meta templates / Double Template for Node.js by Shimon Doodkin,

 the idea is to have a template like php mixed with html
 a template that processed twice, 
  1st time prepeared with static data 
  2nd time - each time a request is made.
 my requirement was a minimal learnign curve.
 the template is planed for nodejs to be prepeared once and used many times 

 i decided on <??> tags for runtime part of the template
 i decided on <%%> tags for prepeare part of the template

 example template:
 hello <? if(myvar) { ?><?=myvar?><? } else { ?> world<? }?>

 complex template example with paritials and recursion:
 a website with satic recusive menu and dynamic content in the center

 <head><title>complex template example</title></head>
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <td dir="rtl" style="padding:10px;text-align:right;direction:rtl"><?=content?></td>
        <td dir="rtl" width="225" bgcolor="#ccd5f4" style="padding:10px;text-align:right;direction:rtl">
          function print_menu(menu1)
           var echo; //redefine local echo variable
           for(link in menu1)
             <li><a href="<?=link.href?>"><?></a></li>
           return echo;
          echo+=print_menu(menu); // echo is defined in the begining of the function and returned at the end of the function. 

  // vars is an argument of the template function,  it is extracted at the begining of function.
  // it calls for other auto preloaded template paritial, with same variable you have in this function
  // for more information see buildtemplate function below.

 to include in in nodejs i use:
 //  require.paths.unshift(__dirname); //make local paths accecible
 //  require('filename')  // include file - filename is without '.js' extention!!!
 // var fs = require('fs');    // lets open files
 var te = require('doubletemplate');  //load double teplate module
 var doubletemplate=te.doubletemplate; // export double template function to global

example of useing parsedir function:

in the code you use:
 also you could have dotnet like componetns if you do like:
 var localstate={};

 the code is in stright forward logic you can read it and understand how it works.
Something went wrong with that request. Please try again.