> >> Anyone know if it's possible to do while loops in velocity templates? > > > > The #foreach directive is the only looping construct provided by > > velocity. > > Can you describe what you are trying to do in more depth? There might > > be a > > way of making it work for you without it being a (dirty) hack. > > > > ~> Most certainly. I have a table "X" that has a foreign link column > "ParentX" (foreign-key-> XID). While > $myXinstance.xrelatedbyParentX()!=null, I want to print out > X.description. Currently I've hacked it into my screen (do the while > loop in the screen, and store a List in the context), but I'll likely > run into a similar situations frequently (this was the first time I used > a VM loop, and it came up right away). >
So, if I understand correctly, you have a table, call it xxxx: XID, integer, primary key description, text ... parentX, integer, refering to XID in a different row of the same table. So, are you saying you want a list of parents recursivly up the tree? Are you making torque calls for each individual row? You might want to add a method to the torque peer class for the table to retrieve the list of torque objects (or just descriptions, if that's all you need) for you. Then at least you won't have to duplicate it in each screen. You can *probably* write a SQL statement to retieve all the records you are intested at once and use the village api to get the results, which will help save trips to the databse. Depending on what database you are using. In any case, velocity is intended to operate on prebuilt lists, which makes sense from a template designer pointer of view (they don't need to see that code). ...mch... --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
