Forum OpenACS Q&A: Re: double deference in template

Collapse
Posted by hsin wang on
@Gustav

That was the closest I could get this, but as my post mentions, I would prefer avoiding sql aliases and let the developer decide what to pass to the template. The reasoning for this is that I may have a query saved in an xql that I use in multiple locations. Requiring my query to provide aliases takes away from flexibility. Maybe my logic behind is flawed, and if that is the case please enlighten me.

@Brian

I read the templating documentation on the Include tag pretty thoroughly, but I'm still having trouble double dereferencing.

The example code I posted is actually exactly all I needed. If there backslashes I'm supposed to put in the right place, I haven't figured out where to put them.

I haven't looked at the template::widget procs, but I'm essentially writing my own widgets, base widgets upon which I can build page-specific elements with other libraries. For example, my SELECT component can later go into another template that eventually transforms the SELECT to a jQueryUI element.

I was hoping to avoid building everything in TCL, as it seems to get messy pretty quickly, although I understand that to be merely an opinion. Maybe my approach is wrong altogether?

Collapse
Posted by Brian Fenton on
Hi Hsin

ok, I just tested your code, and it worked perfectly for me. I'm not using latest OpenACS, but that shouldn't be an issue. The only other difference is that I put the include in the same directory.

Here's what I did:
1. create aaa.tcl with 2 multirows:
# get users
db_multirow users nx {
  select user_id as id, username as label from users
  where rownum < 6
}

db_multirow users2 nx {
  select user_id as id, username as label from users
  where rownum < 3
}

2. create aaa.adp with this:
<include src="bbb" &datasrc="users" />
<hr>
<include src="bbb" &datasrc="users2" />

3. create bbb.adp with this:
<select>
        <multiple name="datasrc">
              <option value="@datasrc.id@">
                    @datasrc.label@
              </option>
        </multiple>
</select>

Output is a HTML page with 2 select boxes. Works perfectly!