On Thu, Aug 12, 2004 at 02:00:06PM -0500, IRA wrote:
> It's just this sort of problem that makes me wonder if the people
> building aolserver ever actually USE aolserver to build web
> applications. It seems like not that big of a deal . . . until you
> realize that we do this ALL THE TIME.
> Here's an example from our code:
>
> if {$vlCountryCode == "DE"} {
> ns_puts "<td background=\"$imageDir/hdr_bg.gif\" valign=\"top\"
> align=\"right\"><a
> href=\"http://www.aol.de/action_templates/globalhelp_1.jsp?cid=1041541\"
> target=\"top\"><img src=\"$imageDir/btn_helptop.gif\" width=$img2w
> height=$img2h border=0 alt=\"$str6\"></a></td>"
> } elseif {$vlCountryCode == "FR"} {
> ns_puts "<td background=\"$imageDir/hdr_bg.gif\" valign=\"top\"
> align=\"right\"><a
I'm rather astonished that you'd ever be writing code like that at
all. Using ns_puts to conditionally write slightly different big
hunks of HTML, all hard-coded inline? Yuck.
If I was limited to just the stock Tcl and AOLserver code, and
couldn't even write my own little helper procs, I'd probably either
use 'subst' or assemble the HTML chunks a bit at a time with 'append'
and curly braces, e.g.:
set td_html {<td background="}
if { [string equal $vlCountryCode "DE"] } {
append td_html $imageDir
append td_html {"/hdr_bg.gif" valign="top" align="right">
<a href="http://www.aol.de/action_templates/globalhelp_1.jsp?cid=1041541"
target="top"><img src="}
# TODO: Etc.
But in practice I probably wouldn't do that either. Constants like
"hdr_bg.gif" repeated several times in different branches of the if
statement? More yuck.
This is why tools like the OpenACS Templating System exist. But if
you, say, really want to use something like ns_write and thus don't
want to use the Templating System, OpenACS has plenty of smaller,
lower level helper procs to help you out with dynamically generated
HTML.
I don't even know what they call it, but I've long heard that the AOL
guys (the Digital City team?) have their own internally developed
toolkit to do more or less the same sort of stuff as OpenACS. Don't
you AOL folks use it?
And if I didn't have OpenACS (or something like it) available, I would
at least whip up a few of my own simple procs to help refactor and
de-obfuscate the code.
--
Andrew Piskorski <[EMAIL PROTECTED]>
http://www.piskorski.com/
--
AOLserver - http://www.aolserver.com/
To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: field of
your email blank.