Page 1 of 1

calling nvelocity engine

Posted: Sat Jan 29, 2011 3:27 pm
by RickSilver
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

Re: calling nvelocity engine

Posted: Mon Jan 31, 2011 6:17 am
by plugables
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);


Re: calling nvelocity engine

Posted: Mon Jan 31, 2011 7:08 pm
by RickSilver
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();

Re: calling nvelocity engine

Posted: Fri Feb 04, 2011 8:49 am
by mazhar
When adding parameters in following statements

Code: Select all

parameters.Add("Store", store);
parameters.Add("Order", order);
try to keep parameter names in lowercase and try again like this

Code: Select all

parameters.Add("store", store);
parameters.Add("order", order);

Posted: Fri Feb 04, 2011 6:35 pm
by RickSilver
Thank you Mazhar! That was it. It works now.

Re: calling nvelocity engine

Posted: Mon Feb 07, 2011 4:21 am
by mazhar
Awesome!