Does NVelocity no longer support string templates?

We have a bunch of NVelocity templates in the embedded resources we use for emails. We want to transfer these templates to the database so that users can easily configure users.

It seems that NVelocity (lock port) does not support strings as patterns. Does anyone know how to do this.

To be clear, this is what I want to do (the syntax may be inaccurate, I go from memory) ...

string templateString = "Hello $!user";
Template template = new Template(templateString);
string results = template.Merge(....);
+5
source share
2 answers

This works for me:

using System.Collections;
using System.IO;
using NUnit.Framework;
using NVelocity;
using NVelocity.App;

[Test]
public void StringParsing()
{
    var h = new Hashtable {
        { "foo", "Template" },
        { "bar", "is working" },
        { "foobar", new[] { "1", "2", "3" } } };
    Velocity.Init();
    var c = new VelocityContext( h );
    var s = new StringWriter();
    Velocity.Evaluate( c, s, "",
        "$foo $bar: #foreach ($i in $foobar)$i#end" );
    Assert.AreEqual( "Template is working: 123", s.ToString() );
}
+15
source

After much research on my own, the NVelocity lock port seems like it will be a huge PITA to get a pattern from a string in memory.

NVelocity StringTemplate. , : http://websitelogic.net/articles/MVC/stringtemplate-viewengine-asp-net-mvc/

0

All Articles