tcl-websh-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ronnie Brunner <>
Subject Re: putx substition style
Date Fri, 21 Dec 2001 12:33:28 GMT
> My current thinking on the situation is that there are two good ways
> to mix up Tcl and HTML.
> 1) Using <? ?> (as per
> )
>    This is the proper way to do 'processing instructions' for XML.  I
>    regard this model as the 'full integration' model, because it lets
>    you add things quite naturally to an HTML document, and also
>    because it's necessary - at least if you want to be able to loop or
>    do conditionals on chunks of HTML outside the <? ?> - to add
>    everything up as either bits to execute or 'puts' statements.

This makes sense and is kind of what we now have in the form of { } or
<% %>. I have no problem with declaring this being <? ?>. Right now we
provide even a configuration option, so in principle we can provide
almost any combination. One thing that we do not have is that you can
actually place your code *around* HTML. We only allow it *in* HTML:

we do have:
   <? set x 0 
      while { $x < 5 } { 
        web::put "\$x = $x<br>"
        web::put "\n\nLOOP<br>\n\n"
        incr x
      } ?>

we do not have:
   <? set x 0 
      while { $x < 5 } { 
        web::put "\$x = $x<br>" ?>


   <? incr x } ?>

> 2) Substitution, using 'subst' on the text directly.
>    This is more immediate, and quicker if one just wants to substitute
>    some variable values (possibly having taken care of the logic
>    elsewhere).
> I would encourage future directions to take after both of these, as
> they both have their uses, and to discourage other systems (for
> instance, ASP style delimiters, {}, <+, or whatever else).
> By the way, what is to be gained from using {} instead of just
> web::put " [something blah] ...." ?

This is a more complicated issue...

> For instance:
>         web::putx {
>             <h1>Top secret session information</h1>
>             <dl>
>             <dt><b>Id</b>
>             <dd>{web::put [web::statef::id]}
>             <dt><b>Name</b>
>             <dd>{web::put [web::statef::get name]}
>             <dt><b>Age</b>
>             <dd>{web::put [web::statef::get age]}
>         }

web::putx is what's needed to "eval" some HTML code. In your first
example, web::putx would be needed to "eval" a template such as

        web::putx {
            <h1>Top secret session information</h1>
            <dd><? my_command_to_get_and_put [web::statef::id] ?>
            <dd><? web::put [web::statef::get name] ?>
            <dd><? format_and_put_the_age [web::statef::get age] ?>

in general, what we run putx on can be a complete file (putxfile) or a
template sniplet or whatever.

> Could be 
>         web::put [subst {
>             <h1>Top secret session information</h1>
>             <dl>
>             <dt><b>Id</b>
>             <dd>[web::statef::id]
>             <dt><b>Name</b>
>             <dd>[web::statef::get name]
>             <dt><b>Age</b>
>             <dd>[web::statef::get age]
>         }]

This is uncool for the above eyample, because I don't want to care
about escaping the use of '[' and '$' in a template. The template must
be plain HTML (or XML ...) w/o any special escaping

However, using it from whithin code, we would certainly take this
approach and just implement this as

        web::put "
            <h1>Top secret session information</h1>
            <dd>[web::statef::get name]
            <dd>[web::statef::get age]

But this is a different thing: here we just put a string, whereas in
the first example, we want to process a template.

> Personally, I am happier when I can rely on native Tcl functionality
> to do things for me.

I certainly agree for the second example.

In conclusion, I'm not sure whether it makes sense to have three
different types of output generation as you suggest:
	  - process template (web::putx)
	  - output a string (web::put)
	  - subst and output a string (not implemented)
imho: forget about the "web::subst_n_put".

Ronnie Brunner                     
Netcetera AG, 8040 Zuerich    phone +41 1 247 79 79 Fax: +41 1 247 70 75

View raw message