Forum OpenACS Development: New template tag ideas

Collapse
Posted by Tom Jackson on

Hey, even though I should know better, I keep messing around with new tags. Doing this I seem to have stumbled upon some interesting ones.

First I noticed the tcl tag seems to have a bug. it looks for something like:

<tcl>= some code here </tcl>
or content that begins with '=' and then just removes all the spaces and joins them. The above code would result in somecodehere being displayed on the page.Otherwise the tcl tag runs the code but doesn't print anything on the page. I simplifed the tag code to just run the code and not look for the '=', and I renamed the tag <!>, since nothing prints, dumb but short.

I created a new tag that probably does what the broken tcl tag is supposed to do: execute and return. I named this tag <=>.

One thing you can't do in the templating system with ease is to get an array element whose name comes from a multiple element of the form @multi.element@. With the tcl or = tag, you can do:

<tcl>set a b(@c.d@)</tcl>
<=>set a b(@c.d@)</=>

However, it seems messy to rely on the return value of the set command to print what you want, so here is an alternative tag:

<@>b(@c.d@)</@> if @c.d@ is e, 
 returns the value of b(e)
<@>i</@> retuns the value of i

Finally, just in case someone needs to run subst:

<subst>The time is now [ns_time]</subst>

Now here is an interesting feature that I never noticed before. Some users complain that the adp templating system doesn't work like the asp one. It just doesn't allow you to arbitrarily escape into tcl and back into html. Well, it appears that this isn't true when using the OpenACS templating system. Here is a simple example, with a minimum .tcl file, the adp includes:


<!>set i 0</!>

<!>while {@i@ < 5} { </!>

<p>@i@</p>

<!>incr i

}</!>


<p>i is now: '<@>i</@>'
<p><subst>the time is now [ns_time]</subst>
<p>i + 1 = '<=>expr @i@ + 1</=>'.

You can check the results

Collapse
2: Re: New template tag ideas (response to 1)
Posted by Dave Bauer on
Can't you use
<% some tcl code here %>
and
<%=$tcl_var%>

in adp pages?

Collapse
3: Re: New template tag ideas (response to 1)
Posted by Dave Bauer on
Not that I recommend putting Tcl in ADP templates. I haven't found a page that could not be written keeping all Tcl code out of the ADP page.
Collapse
4: Re: New template tag ideas (response to 3)
Posted by Jeff Davis on
I looked and the tcl tag is not used anywhere in OpenACS and to be honest I think I am quite happy about that. I think most html formatting tools will not look through <% tags but they will definitely mess with stuff bound by <tcl> I would be inclined to remove it.

And as Dave said, we would like to see less tcl (i.e. none) in the .adp files so if there is something that is hard to do with the current tag set we should add a tag to make it easy, not force designers to deal with tcl arcana.

I would argue for removing the tcl tag and not adding any of these interesting but I think ultimately troublesome tags you are proposing.

Collapse
6: Re: New template tag ideas (response to 4)
Posted by Dan Wickstrom on
IIRC, the <tcl> tag can't be removed as <%, %> escapes are replaced with the <tcl>, </tcl> tags prior to compiling the template.
Collapse
5: Re: New template tag ideas (response to 1)
Posted by Tom Jackson on

I agree with both of you. Actually I didn't realize that the @a.b@ syntax worked inside of the <% tags, but it is noteable that you can't get at an array without resorting to tcl and variables can't represent functions, but I haven't come up with a real world situation where this is actually needed.

Jeff: I'll leave the disturbing creation in a safe place under wraps.

I just checked with AOLserver 4.0. The <% tags seem to require complete expressions. I remember some discussion of how 4.0 didn't allow different adp parsers, and the only form supported was for each chunk to be complete. Is this going to affect OpenACS under AOLserver 4.0?

Collapse
7: Re: New template tag ideas (response to 1)
Posted by Tom Jackson on

That explains quite a lot. So the parser should work in AOLserver 4.0.