Hi John,

Thanks for the help.  I found the problem.

In my object model, I have the concept of nested templates.  In order
to support this, I flatten this tree of templates into a list.

For each template in the list, I combined them into one big template
using the Merge method.  But each time I call the Merge method, it
evaluates any directives.  But because my context is not set yet, the
wrong conditional decisions are made.  Finally, when I merge the big
template with the context, all the conditional directives have been
evaluated.  This is why I got the strange behavior.

Thanks again.



On Sep 13, 1:11 am, John Simons <[email protected]> wrote:
> Hi An,
>
> As far as I know there shouldn't be any difference from running NVelocity in a
> console vs hosted in ASP.NET.
> Have you tried to hardcode true, and see what happens:
> dataContext.Add("hasShippingInfo", true);
>
> Cheers
> John
>
> ________________________________
> From: An Phu <[email protected]>
> To: Castle Project Users <[email protected]>
> Sent: Mon, 13 September, 2010 2:54:26 PM
> Subject: Re: NVelocity not evaluating #if condition correctly.
>
> Sorry, the output is just
>
> hasShippingInfo : True
>
> It does not have the <P> tags and the rest.
>
> On Sep 12, 9:52 pm, An Phu <[email protected]> wrote:
>
>
>
>
>
>
>
>
>
> > Hello,
>
> > I have been struggling with this all weekend.  I am hoping someone can
> > help me with this.  I have the following template.
>
> > hasShippingInfo : $hasShippingInfo
> > #if($hasShippingInfo)
> > <P style=""FONT-FAMILY: Arial, Verdana, sans-serif; COLOR: #252525;
> > FONT-SIZE: 12px"">
> >         <B>Shipping Method:</B> $ShippingMethod<BR>
> > </P>
> > #end
>
> > The output I got is
>
> > hasShippingInfo : True
> > <P style="FONT-FAMILY: Arial, Verdana, sans-serif; COLOR: #252525;
> > FONT-SIZE: 12px">
> >         <B>Shipping Method:</B> FedEx<BR>
> > </P>
>
> > It seems that NVelocity is not evaluating the if condition correctly.
> > It returns false even though $hasShippingInfo is true, as shown in the
> > output.
>
> > The code I am using is as follows:
>
> >             // this data context is initialized somewhere else.
> >             var dataContext= new Hashtable();
> >             dataContext.Add("hasShippingInfo", hasShippingInfo);
> >             dataContext.Add("ShippingMethod", "FedEx");
>
> >             // the following code snippet are part of a emailer.
> >             var context = new VelocityContext(DataContext);
>
> >             Velocity.Init();
>
> >             using (var writer = new StringWriter())
> >             {
> >                 if (!Velocity.Evaluate(context, writer, string.Empty,
> > Template))
> >                 {
> >                     throw new Exception(string.Format("NVelocity
> > encountered errrors evaulating template:\n{0}", Template));
> >                 }
>
> >                 content = writer.ToString();
> >             }
>
> > When I take code out and put it into a console app, it works.
> > NVelocity evalutes #if($hasShippingInfo) correct.  In other words,
> > $hasShippingInfo is true and the whole #if condition is true, and my
> > output is rendered.
>
> > But when I use it in an Emailer, that is used by a ASP.NET site, it
> > fails.  NVelcoity evaulates the #if condition as false even though
> > $hasShippingInfo is true.
>
> > Any help is much appreciated.
> > An
>
> --
> You received this message because you are subscribed to the Google Groups
> "Castle Project Users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group 
> athttp://groups.google.com/group/castle-project-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to