One thing I come across alot in other peoples coding is the lack of templating. Programs that have the HTML hardcoded into it, making the programs inflexible and a pain to customize.
Whenever I code, every piece of HTML outside of table internals ( and sometimes even them ) is templated. It makes code easier to read, and the software easier to work with.
If you are one of those people who hardcode their HTML allow me to atleast give you a head start to my perceived path of "good" cgi programming.
The template subroutine I use basically has these two lines of code in it:
To insert the values of a var, %varname% is the command I use, and this is a working regexp that I haven't been able to break to insert the data.
$line =~ s/\%([a-zA-Z0123456789\_\:]*)\%/${$1}/gi;
And to insert the values of an hash, !array{key}! is the command and here is a regexp that MAY be breakable. I use this one for selects alot ( ie <option !selectcountry{USA}!> in the html, and in the CGI program $selectcountry{$FORM{country}} = "selected"; )
$line =~ s/\!([^ ]*)\{([^ ]*)\}\!/${$1}{$2}/gi;
Please, for the love of Pete ( full pun intended ) use templates if you code CGI programs that make it into the wild.
Pete
insert into pete values('red hair','near green eyes','overinflated ego');
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Meditations on templates
by OeufMayo (Curate) on Apr 19, 2001 at 13:46 UTC | |
by davorg (Chancellor) on Apr 19, 2001 at 13:51 UTC | |
by tilly (Archbishop) on Apr 20, 2001 at 03:54 UTC |