NVelocity template error in c#

400 views Asked by At

I am fairly new in using NVelocity. I am trying to edit some of the old templates for my company and i ma getting this error which i dont understand. OK so in template, if order has multiple shipments then show multiple shipment name and if only one then show only one shipment name. when there is multiple shipments, it works fine BUT when there is only one then somehow template does not renders the required shiment name instead printout the class name.

 #if($order.Shipments.Count > 1) 
 #foreach($shipment in $order.Shipments)
 #beforeall 
 #each 
 $shipment.ShipMethodName <strong>|</strong> 
 #else
 $order.Shipments[0].ShipMethodName  // in emails it renders "Orders.OrderShipmentCollection[0].ShipMethodName"
 #end
 #end

Please help.

1

There are 1 answers

0
Jonathon Rossi On BEST ANSWER

I know this is an old question, but in case someone is looking for a solution later I thought I'd post an answer as I was going through old questions that don't have accepted answers. I don't how I didn't notice the error when I posted that comment in September last year.

$order.Shipments[0].ShipMethodName is giving you Orders.OrderShipmentCollection[0].ShipMethodName because NVelocity doesn't support indexers like C#, you need to use the get_Item() method, i.e. $order.Shipments.get_Item(0).ShipMethodName that is the underlying method the C# compiler creates for indexers.

What is happening is $order.Shipments prints out the type name (Orders.OrderShipmentCollection) and the rest [0].ShipMethodName just gets printed verbatim.