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

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


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

  <p bind="message"/>

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

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

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

which might become:

  <p>message number one</p>

  <p>another message</p>

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

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

  name: joe
  sex: m
  age: 22

  name: alice
  sex: f
  age: 19

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?



More information about the Melbourne-pm mailing list