Search code examples
asp.netvelocitynvelocity

Prevent NVelocity from displaying Tokens


I have the following piece of code in my template that uses NVelocity to process form data:

$PartnerProfile.Nvalue("Name")

In case the Nvalue method doesn't return any value, I want NVelocity to display nothing. But it rather outputs the code, i.e.
"Lorem ipsum dolor sit $PartnerProfile.Nvalue("Name") amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt"

How can I prevent that code to be displayed in my output?


Solution

  • The answer is very simple. I just need to add the character '!' to the beginning of the token. Like this:

    $!PartnerProfile.Nvalue("Name")
    

    The output in case there's no value for the indicated parameter will be empty.

    "Lorem ipsum dolor sit $PartnerProfile.Nvalue("Name") amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt"

    will be this -->

    "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt"