I am manually obtaining a template and then emailing it in order to replace a custom variable in it. Done this way, it is not automatically run through the nvelocity engine to replace items like store and order information. If my template has this store and order information and my custom variable, is there a single call I can make to get the store and order information, including the itemized list, or do I have to do this replacement and looping myself?
Thanks
Rick
calling nvelocity engine
Re: calling nvelocity engine
You will have to add the Store and Order variables to the nvelocity context.
Code: Select all
Store store = Token.Instance.Store;
Order order; // the order object. Initialize it accordingly
NVelocityEngine nve = NVelocityEngine.Instance;
Hashtable parameters = new Hashtable();
parameters.Add("Store", store);
parameters.Add("Order", order);
string processedData = nve.Process(parameters, tmplate);
-
- Lieutenant (LT)
- Posts: 66
- Joined: Mon Jun 22, 2009 5:49 pm
Re: calling nvelocity engine
Here is my code. It is NOT replacing the store and order variables. Do you see what I am doing wrong?
Order order = OrderDataSource.Load(e.OrderId, false);
Store store = Token.Instance.Store;
NVelocityEngine nve = NVelocityEngine.Instance;
Hashtable parameters = new Hashtable();
parameters.Add("Store", store);
parameters.Add("Order", order);
emailTemplates[0].Body = nve.Process(parameters, emailTemplates[0].Body);
emailTemplates[0].Send();
Order order = OrderDataSource.Load(e.OrderId, false);
Store store = Token.Instance.Store;
NVelocityEngine nve = NVelocityEngine.Instance;
Hashtable parameters = new Hashtable();
parameters.Add("Store", store);
parameters.Add("Order", order);
emailTemplates[0].Body = nve.Process(parameters, emailTemplates[0].Body);
emailTemplates[0].Send();
Re: calling nvelocity engine
When adding parameters in following statements
try to keep parameter names in lowercase and try again like this
Code: Select all
parameters.Add("Store", store);
parameters.Add("Order", order);
Code: Select all
parameters.Add("store", store);
parameters.Add("order", order);
-
- Lieutenant (LT)
- Posts: 66
- Joined: Mon Jun 22, 2009 5:49 pm
Re: calling nvelocity engine
Awesome!