[Prev][Next][Index][Thread]

Re: [OFF] HTML template languages



Hello Scott,
   I've been interested in CGI programming with Dylan for a while now 
and it always seemed like dylan would be a great language for web work. 
The trouble as you noted is how to separate the programming pieces from 
the presentation. Not a very easy thing to do and I have been all over 
the map in my attempts.
   When I started, I used Perl like most people and had all of my html 
embedded in a script. This always seems like the easiest approach until 
you have to edit your html pages and then you need to hunt down the 
appropriate section and html fragment. I then started working with 
dylan and produced an html module that would allow me to represent a 
page with a vector of html objects with write methods for each type of 
object. This was actually kind of nice as it gave a lot of programming 
freedom and the ability to adjust things very precisely. You could 
compensate for older borwsers, text based browsers, quirks, by simply 
writing a specialized write method on the type of browser looking at the 
page. Very cool. But designers don't want to learn how to change their 
html code into dylan objects, so it ran out of steam.
   Since then, I picked up on two other techniques - ASP and perl 
templates. ASP is kind of nice in that you can write all of your code in 
one file and they have some builtin functions that make formatting your 
data easy. But it is much like the early approach where I am embedding 
script inside html. Some of the same problems exist with being able to 
edit your html will not disturbing the embedded code. 
   With the perl templates technique, I have created the largest 
separation between the html and the script. I create html templates 
that simply hold perl variables inside of a comment so that while 
I am building the page, the code is not present. Inside my script 
for delivering the template, I set each variable inside my template 
to a value and then using the &Template routine, I slurp in the 
template and replace all the perl variable placeholders with there 
values. I've used this technique fairly successfully and it makes 
editing html documents much easier because there is no code to wade 
through. But it does have the limitation of not being flexible. I 
cannot specify anything inside the html pages which has not already 
been defined inside the delivery script. 
    How could dylan beat them all? If I could get a dylan program to 
go through a html document and create all of the dylan html objects with 
the ability to have some dylan expressions as those objects contents,
then 
you could maintain the separation between the design and the
programming. 
I wish I had the time to pursue this further, but I'm not able to at
this 
point. However, I still think it would be a cool thing.

James   

Scott Ribe wrote:
> 
> So what do others think?
> 
> I just made a crack about the ugliness of "JavaScript and similar
> approaches
> where HTML contains a tag that contains a script that "prints" HTML out
> as a side effect" as part of a longer rant. I'm not fond of any form of
> "program" that "prints" out HTML, whether Perl or Python or Tcl. And I
> consider nesting that within HTML itself horrible.
> 
> Here's a real-life example of my preferred approach:
> 
> <TABLE BORDER=1 CELLSPACING=0 CELLPADDING=3>
>         <TR><TH COLSPAN=4 ALIGN=CENTER>Pagers: <!--Count([Pagers])-->
> found</TH></TR>
>         <TR>
>                 <TH>Name</TH>
>                 <TH>Dept</TH>
>                 <TH>Phone</TH>
>                 <TH>Pager</TH>
>         </TR>
>         <!--ForEach([Pagers])--><TR VALIGN=TOP>
>                 <TD><!--[Pagers]Name;ln--></TD>
>                 <TD><!--[Pagers]Dept;ln--></TD>
>                 <TD><!--[Pagers]Phone;l--></TD>
>                 <TD ALIGN=CENTER>
>                         <!--If([Pagers]CanPage)-->
>                                 <A HREF="editmsg.4ds?[Pagers]Num=<!--[Pagers]Num-->">
>                         <!--/If([Pagers]CanPage)-->
>                         <!--[Pagers]Num;l-->
>                         <!--If([Pagers]CanPage)-->
>                                 </A>
>                         <!--/If([Pagers]CanPage)-->
>                 </TD>
>         </TR><!--/ForEach([Pagers])-->
> </TABLE>
> 
> A couple of notes:
> 
> I put my tags in HTML comments because I was a newbie to this and was
> trying to come up with the form that would be least objectionable to
> HTML verifiers and WYSIWYG editors. This was a complete failure and I've
> since figured out that I shouldn't have even tried.
> 
> The [table]column syntax rather than the more common table.column just
> mirrors the underlying database/4GL syntax. What follows the ; are
> formatting options.
> 
> One product whose approach I actually like is at http://www.heitml.com/.
> In essence, what I envision is rather like HeiTML but with Dylan syntax
> for the language and with templates preprocessed and compiled per Bruce
> Hoult's comments.



Follow-Ups: References: