Forum OpenACS Development: Modified behavior of templating tags in newer OpenACS versions?

Dear Community,

we have recently upgraded to OpenACS 5.9.1b3. In our code base, there is often the following usage of the <if> templating tag:

<if @item_id@>...</if>

I personally don't like this coding style, but others in our team do. Obviously the new OpenACS version handles this differently than the old one: while before <if 123> was true, it is now false. Although I think I remember that I have read something related to this change in the past, I cannot find any documentation or release notes concerning this topic.

Is my assumption correct, that I have to find all these places in the code an replace them with something like <if @id@ ne "">? Are there any other similar pitfalls?

The syntax is not conformant to the tag definitions [1]. I think it was silently introduced a view years ago. There is/was a large variety of styles of Boolean comparison in adp-files, many of those variants were cleaned up, made explicit over the last years [2]. It is not clear, what <if @item_id@> should mean: is it empty (as you suggest? is it non-zero? or is the variable set? So, making these tests explicit helps to understand the code and improves maintainability. Probably, the example above should raise an error/warning, since it is not covered by the OpenACS tag expression rules. I will look into this, when time permits.

If there are many such places in your code basis, you might find the following script helpful for detecting/fixes such cases. Although this script covers for the Boolean cases, it is straightforward to include item_id tests similar as in rule 1. The script works through all the .adp files in the current directory (pr below).

btw,.i would not recommend to upgrade to the beta version (5.9.1b3), but to upgrade to the released version OpenACS 5.9.1.

all the best
-gn

[1] https://openacs.org/doc/acs-templating/tagref/if
[2] https://cvs.openacs.org/qsearch?q=boolean+tag&t=1&project=

#!/usr/bin/env tclsh
# script to change boolean tags
# Gustaf Neumann,   Dez 2010

array set opt {-reset 0 -change 1 -path . -name *adp -diff 0}
array set opt $argv

if {$opt(-reset)} {
    foreach file [exec find -L $opt(-path) -type f -name *-original] {
        regexp {^(.*)-original} $file _ new
        file delete $new
        file rename $file $new
    }
}

if {$opt(-diff)} {
    foreach file [exec find -L $opt(-path) -type f -name *-original] {
        regexp {^(.*)-original} $file _ new
        set status [catch {exec diff -wu $file $new} result]
        puts "---diff -wu $file $new"
        puts $result
    }
    exit
}

if {$opt(-change)} {
    set totalchanges 0
    set files 0
    foreach file [exec find -L $opt(-path) -type f -name $opt(-name)] {
        puts processing-$file
        set F [open $file]; set c [read $F]; close $F
        set origContent $c
        set newFile ""
        set changes 0

        incr changes [regsub -all {<if @([a-zA-Z0-9_.]+_p)@>} $c {<if @\1;literal@ true>} c]
        incr changes [regsub -all {<if @([a-zA-Z0-9_.]+_p)@ eq ("t"|t|"1"|1)>} $c {<if @\1;literal@ true>} c]
        incr changes [regsub -all {<if @([a-zA-Z0-9_.]+_p)@ eq ("f"|f|"0"|0)>} $c {<if @\1;literal@ false>} c]
        incr changes [regsub -all {<if @([a-zA-Z0-9_.]+_p)@ (true|false)>} $c {<if @\1;literal@ \2>} c]

        if {$changes > 0} {
            puts "... updating $file ($changes changes)"
            set F [open /tmp/XXX w]; puts -nonewline $F $c; close $F
            file rename $file $file-original
            set F [open $file w]; puts -nonewline $F $c; close $F
            incr totalchanges $changes
            incr files
        }
    }
    puts "$totalchanges changes in $files files"
}
Thank you for your answer and the script, which helped a lot in the investigation of the problem.

Meanwhile, I think I have found the related changes. Firstly,

string is true -strict
is now used instead of
template::util::is_true
at the relevant place in the code.

https://cvs.openacs.org/browse/OpenACS/openacs-4/packages/acs-templating/tcl/tag-procs.tcl?u=3&r1=1.20&r2=1.20.2.1

However, also

template::util::is_true
isn't as broad as it was in the past and has been "streamlined" to use the Tcl validation.

https://openacs.org/api-doc/proc-view?source_p=1&proc=template::util::is_true&version_id=

So, while it would be easily possible to revive the old behavior at these places, I will go the more future-proof road of changing the about the 200 affected files...

Thanks!