[stringtemplate-interest] Presenting relationships between two lists
Robert Rowland
robertdavidrowland at gmail.com
Tue Jun 27 04:37:19 PDT 2006
Hi All,
Before I go on too much further can I just say that I'm not after
reopening the old argument about conditionals . . . I can understand
quite clearly why they are a "bad thing".
However I've got a problem here that with other template systems I
would have used conditionals, and can't seem to get my head round how
to get this to work with StringTemplate.
I have two lists of objects, with a one to one relationship between
the items in the lists. Lets say they are reports and users. I want
to produce a list of reports and against each report is a list of all
the users. For each report one of those users is marked as selected.
So here goes:
$reports:{r|
$r.reportName$
$users:{u|$u.userName$ $if(u.userName==r.userName)$Yes Selected!$endif$
}$
}$
Obviously the $if(u.userName==r.userName)$ doesn't work in
StringTemplate, but I can't for the life of me work out how to get the
same behaviour without the conditional.
Hopefully I'm making sense . .
Cheers Rob.
p.s. in case your wondering, and in case it makes things clearer, what
I'm actually trying to achieve is HTML select boxes, so . . .
$reports:{r|
$r.reportName$
<select name="$r.id$>
$users:{u|<option
value="$r.id$-$u.id$">$if(u.userName==r.userName)$
selected$endif$>$u.userName$</option>
}$
</select>
}$
Which may produce something like the following . . .
My Report 1
<select name="r1">
<option value="r1-u1" selected>Rob</option>
<option value="r1-u2">Fred</option>
<option value="r1-u3">George</option>
</select>
My Report2
<select name="r2">
<option value="r2-u1">Rob</option>
<option value="r2-u2">Fred</option>
<option value="r2-u3" selected>George</option>
</select>
More information about the stringtemplate-interest
mailing list