[Melbourne-pm] a perl html template processor I wrote

Sam Watkins swatkins at fastmail.fm
Tue Apr 29 05:14:59 PDT 2008


hi,

I wrote an html template processor for a CGI/perl job,
it can do things like:


  <p bind="message"/>

  <table>
  <tr bind="sql:select foo, bar from tab">
    <td>$foo</td> <td>$bar</td>
  </tr>
  </table>

  <p bind="file:some_text.txt"/>

  <pre bind="people">
  name: $name
  sex: $sex
  age: $age
  </pre>


which might become:


  <p>message number one</p>

  <p>another message</p>

  <table>
  <tr>
    <td>frog</td> <td>99</td>
  </tr>
  <tr>
    <td>cow</td> <td>42</td>
  </tr>
  </table>

  <p>this is the text that
  was in some_text.txt file</p>

  <pre>
  name: joe
  sex: m
  age: 22
  </pre>

  <pre>
  name: alice
  sex: f
  age: 19
  </pre>

There are two ways to get at variables, using $varname and using
bind="varname".  It works with singletons, arrays, objects/hashes, plain
text and html text.

No need for loops; just bind to an array variable.
No need for conditionals; just bind to an array variable that might have
0 or 1 members.


I think it's quite a nice system, the syntax and design is simpler than
other template programs I've seen.


My CGI library also handles extra parameters on form buttons, like:

  item 12: <input type="submit" name="Delete__12" value="Delete">

There's no other way to pass button-specific info with a form submit.


Is this interesting to anyone who does web development?


regards,

Sam


More information about the Melbourne-pm mailing list