I knew when I start­ed this project (which was a while ago, I kin­da cheat­ed on this one) that I didn’t want to write out all the HTML myself, I’m not THAT masochis­tic. What I want­ed to do was basi­cal­ly say “make a text box to write the address in”.

So I start­ed with a gener­ic pre­proces­sor. I’ve use pre­proces­sors such as CPP, TeX and Make so fig­ured I would take a gener­ic pre­proces­sor like M4 and define a few HTML macros… prob­lem solved. Unfor­tu­nate­ly it wasn’t that sim­ple and as I added com­plex­i­ty it got hard­er to keep it all straight, par­tic­u­lar­ly the quot­ing.

The basic text box wasn’t too bad.

dnl TEXT_Q(name, label, [length])
define(TEXT_Q, indir(LAYOUT, $1,
    ‘<label for=”$1_text”>$2</label>’,
    ‘<input id=”$1_text” name=”$1ifelse($3, ‘’, ‘’, ‘size=”$3″’)>’

But when I tried to cre­ate option­al group­ings it start­ed to get messy. This is a snip­pit from TABULAR_OPTIONAL_ROWS and call­ing it.

    dnl Build the head­ing rows
    <tr class=“tabular_optional_rows_heading_row”>
    foreach(‘XXXXX’, (dquote(shift($@))), ‘XXXXX’)

    TEXT_Q(salary_abn, Pay­ers Aus­tralian busi­ness num­ber, 11), dnl TODO: Should be Payer’s

With TABULAR_OPTIONAL_ROWS I couldn’t fig­ure out how to have a vari­able num­ber of rows and I couldn’t fig­ure out how to pass it’s options with­out quot­ing so I decid­ed to throw in the tow­el and switch to some­thing else.

I had exper­i­ment­ed with Tem­plate Toolk­it at work using it to inject snip­pits of Javascript into HTML doc­u­ments. In the end I stopped using it and had a sta­t­ic HTML page which includ­ed a ful­ly gen­er­at­ed Javascript file but the short expo­sure I had impressed me and I tried it here. I found it much clean­er, the named para­me­ters cut out a lot of com­plex­i­ty and the abil­i­ty to just drop back to Perl if I want­ed to do some­thing real­ly hairy was nice.

This is the def­i­n­i­tion of a text box fol­lowed by the call­ing syn­tax of a radio box that tog­gles the vis­i­bil­i­ty of the text box.

<tr class=“text” id=[% name %]_row” 
    [%- IF hide -%]
        style=“dis­play: none”
    [%- END -%]
<td class=“ques­tion”>
    <label for=[% name %]_id”>[% text %]</label>
<td class=“answer”>
    <input type=“text” name=[% name %] id=[% name %]_id”>

[% INCLUDE tax/radio
    name = “surname_changed”
    text = “Has any part of your name changed since com­plet­ing your last tax return?”
    mod­i­fy = “previous_surname”
    options = [{name => “Yes”, action => “show”}, {name => “No”, action => “hide”}]

[% INCLUDE tax/text
    name = “previous_surname”
    text = “Pre­vi­ous sur­name”
    hide = “true”

The nor­mal syn­tax for options is sim­ply [“Yes”, “No”], the Perl fall­back I men­tioned ear­li­er allows me to have more com­plex syn­tax when I need it but keeps things sim­ple most of the time. I’ve since dis­cov­ered there’s a Tem­plate Toolk­it ver­sion three that’s a nice step for­ward but it’s list­ed as still in devel­op­ment and in a very Alpha state, it also smelt a bit like it was suf­fer­ing from clas­sic sec­ond project woes. I think I’m play­ing with enough new stuff not to add exper­i­men­tal Tem­plate Toolk­it ver­sions to the list.