Forum OpenACS Q&A: Nested multiple tags

Collapse
Posted by Lee Denison on

I have submitted a small patch that lets you nest multiple tags. Enjoy, if it's useful to anyone else.

Collapse
Posted by Arjun Sanyal on
Thanks Lee! Not being able to nest multiple tags was a major annoyance
of the templating system for me...
Collapse
Posted by Don Baccus on
I got the notice of this patch, Lee, but haven't applied it yet.  I plan to clear out my patch backlog by the end of the week.

This sounds very nice.

Collapse
Posted by C. R. Oldham on

Greetings,

This patch appears to break the group creation forms, and might break the auto-generated templating system forms in general. Here is the traceback from the request processor:

can't read "__i": no such variable
    while executing
"if { $__i == ${elements:rowcount} } {
        break
      }"
    ("for" body line 95)
    invoked from within
"for { set __t20_i 1 } { $__t20_i <= ${elements:rowcount}  } { incr __t20_i } {
    upvar 0 elements:$__t20_i elements
  
if {! ([template::util::is_ni..."
    ("uplevel" body line 22)
    invoked from within
"uplevel {
    	  set __adp_output ""
append __adp_output "

<..."
    (procedure "template::code::adp::/home/cro/wd/ncacasi/packages/acs-templ..." line 2)
    invoked from within
"template::code::adp::$file_stub"
    (procedure "template" line 32)
    invoked from within
"template $id $style"
    (procedure "template::form::generate" line 3)
    invoked from within
"template::form::generate add_group"
    ("eval" body line 1)
    invoked from within
"eval template::form::$command $args"
    (procedure "template::form" line 3)
    invoked from within
"template::form generate add_group "
    invoked from within
"append __adp_output "[template::form generate add_group ]""
    ("uplevel" body line 20)
    invoked from within
"uplevel {
    	  set __adp_output ""

    set __adp_master [template::util::url_to_file "../master" "$__adp_stub"]
set __adp_properties(context_bar) "..."
    (procedure "template::code::adp::/home/cro/wd/ncacasi/packages/acs-subsi..." line 2)
    invoked from within
"template::code::${template_extension}::$__adp_stub"
    (procedure "template::adp_parse" line 57)
    invoked from within
"template::adp_parse [file root [ad_conn file]] {}"
    (procedure "adp_parse_ad_conn_file" line 7)
    invoked from within
"$handler"
    ("uplevel" body line 2)
    invoked from within
"uplevel $code"
    invoked from within
"ad_try {
	$handler
      } ad_script_abort val {
	# do nothing
      }"
    invoked from within
"rp_serve_concrete_file [ad_conn file]"
    (procedure "rp_serve_abstract_file" line 60)
    invoked from within
"rp_serve_abstract_file "$root/$path""
    ("uplevel" body line 2)
    invoked from within
"uplevel $code"
    invoked from within
"ad_try {
	rp_serve_abstract_file "$root/$path"
	set tcl_url2file([ad_conn url]) [ad_conn file]
	set tcl_url2path_info([ad_conn url]) [ad_conn path_inf..."

Collapse
Posted by C. R. Oldham on
(close a tag)
Collapse
Posted by Lee Denison on

Thanks for pointing that out. This patch, when applied after the first, fixes the problems with the group tag.

It also allows group tags to be nested in the following ways:

<multiple name="outer">
<group column="field1">
@outer.field1@
</group>
<multiple name="inner">
<group column="field1">
@inner.field1@
</group>
</multiple>
</multiple>

<multiple name="outer">
<group column="field1">
@outer.field1@
<multiple name="inner">
<group column="field1">
@inner.field1@
</group>
</multiple>
</group>
</multiple>

Note the following is valid, however when nesting the same multirow, there is no way to reference the fields from the outer most amultirow from within the nested multiple tags. This limitation is mainly due to the fact that I'm trying to affect the evaluation time of the templates as little as possible.

<multiple name="amultirow">
@amultirow.field1@
<multiple name="amultirow">
@amultirow.field1@
</multiple>
</multiple>

The following is not valid because I don't want to affect the evaluation time of the templates, and because I'm not sure what the semantic meaning of this combination of tags is.

<multiple name="outer">
<group column="field1">
<group column="field2">
@outer.field1@
</group>
</group>
</multiple>
Collapse
Posted by Min Chen on
Hi. I need to use nested multiple tags, but I don't know what I should do with your patch.  Sorry for the newbie question, I am new in TCL programming. Thanks!
Collapse
Posted by Min Chen on
Hi.  I am posting this message again because it seems there was a problem the first time it was posted:

I need to use nested multiple tags, but I don't know what I should do with your patch.  Sorry for the newbie question, I am new in TCL programming. Thanks!

Collapse
Posted by Min Chen on
Hi.  I am posting this message again because it seems there
was a problem the first time it was posted.
Word wrapping is not supported in this bboard?
The sentences seem to be truncated.

I need to use nested multiple tags, but I
don't know what I should do with your patch.
Sorry for the newbie question, I am new in
TCL programming. Thanks!

Collapse
Posted by Lee Denison on

Hi Min,

You need to apply two patches (the first [1] one broke the <group> tag which is then fixed by the second [2]).

Easiest way to apply them is to use 'patch' (see 'man patch'). You can probably get away with:

cd /acs-root/packages
patch -p0 <the-first-patch-file
patch -p0 <the-second-patch-file

Hope that helps.

[1] https://openacs.org/sdm/one-patch.tcl?patch_id=133
[2] https://openacs.org/sdm/one-patch.tcl?patch_id=134

Collapse
Posted by MaineBob OConnor on

Test to close pre tag

<pre>this is pre tag text</pre>
and this is not ???

-Bob

Collapse
Posted by MaineBob OConnor on

Test2 to close pre tag

<pre>this is pre tag text</pre>
</pre> and this is not ???

-Bob

Collapse
Posted by Lee Denison on

The problem seems to be the <table> tag.

This should be okay now.

Collapse
Posted by Neophytos Demetriou on
Patches 133 and 134 were applied over the weekend. I have contacted Min Chen in private...feel free to update your cvs trees and report problems.
Collapse
Posted by Guan Yang on
How do I use this feature with db_multirow? I'd like to do something like this (not actual code):
db_multirow -extend { emails } people people {
    select person_id, first_names, last_name
    from persons
} {
    db_multirow emails emails {
        select email
        from email_addresses
        where person_id = :person_id
    }
}
Collapse
Posted by Tilmann Singer on
In this case you should really do one query and use the "group" tag to avoid unnecessary queries, somehow like this:
db_multirow people people {
  select p.last_name, e.email from
  persons p join email_addresses e on p.person_id=e.person_id
  order by p.last_name
}
and in the adp:
<multiple id="people">

Name: @people.last_name@
Emails: <group column="last_name">@people.email@</group>
<p>
</multiple>

(this example is untested and propably buggy, but you get the idea)
Collapse
Posted by Tilmann Singer on
Please group by person_id and not by last_name like in my example, otherwise people with the same last name will appear in one line ...
Collapse
Posted by Guan Yang on
I know the group tag. I was just wondering whether something like my example was possible, because my queries would be much simpler (it was a simplified example; I actually have 4 tables that would need to be left outer joined).
Collapse
Posted by Lars Pind on
Hi Guan,

No, you can't do what you're suggesting. There can still only be one instance of a multirow with a given anme (in this case 'emails'), so each time you loop over rows in the first db_multirow, you'd be overwriting the inner multirow with the new value.

But looking at the *contents* of your example, what you want to do is probably this:

db_multirow -extend { emails } people people {
    select person_id, first_names, last_name
    from persons
} {
    db_1row email {
        select email
        from email_addresses
        where person_id = :person_id
    }
}
This would work, as would
db_multirow -extend { emails } people people {
    select person_id, first_names, last_name
    from persons
} {
    set email [db_string email {
        select email
        from email_addresses
        where person_id = :person_id
    }]
}
/Lars
Collapse
20: Re: Nested multiple tags (response to 1)
Posted by Tony Wieczorek on
Hi! Does anyone know where we can access those patches any more? The link to the patches don't seem to work, and I'm working on an old version of ACS for which we need to nest multirows. Even just a hint at what the patches did would be great, as I could edit them myself. Thanks!
Collapse
21: Re: Nested multiple tags (response to 20)
Posted by Torben Brosten on
Collapse
22: Re: Nested multiple tags (response to 21)
Posted by Tony Wieczorek on
Thank you very much, Torben!