Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with NVelocity, foreach and two Lists

is there an easy way to solve the following problem.

Let's say I fetch a IList with some books in my controller from my model. Now I want to enrich the output and fetch a preview from Amazon with another model from an outside framework and get another IList.

Now I put both ILists into a property bag.

In NVelocity I use a #foreach for the BookList, but how can I access the amazonbooklist with the right preview? I cannot use $amazonbook[index], where index would be the isbn. Do I really need to put both lists in one big list with a simple onject containing only the two other objects?

Remember, both models are from different frameworks and cannot be placed in one framework. Both frameworks have to stay seperated. I try to solve the NVelocity problem and ofcourse, this problem is just an example, we don't sell books ;)

like image 589
Stefan Koelle Avatar asked Nov 24 '08 21:11

Stefan Koelle


2 Answers

Look here: http://www.castleproject.org/monorail/faq.html#NVelocity%20View%20Engine

You might access a dictionary in NVelocity via

$amazonbook.get_Item($index) 
like image 190
MZywitza Avatar answered Oct 12 '22 13:10

MZywitza


There may be a simpler solution, but I would create a third class like such

class BookList{
       MyBookObject     a;
       AmazonBookObject b;
}

a list of this third class could be passed to your view at once.

like image 36
Ris Adams Avatar answered Oct 12 '22 12:10

Ris Adams