'm interested in learning a bit about the StringTemplate engine, and creating a HTML page which can make use of the StringTemplate using C# in Visual Studio 2013.
I've searched quite extensively, but have been able to to put to together a simple bit of code which will be able to make use of the Library, however I'm receiving a Run-Time error stating.
Content [Anonymous] Attribute String Isn't Defined
I thought I had added the delimiters in the correct places and the correct file path but still seem to getting this error, I'm still new to programming, Have I missed something obvious in my code?
I've been struggling to find a wide range of information on the Library, video examples etc.
Thanks in advance.
I've added the Code below.
static void Main(string[] args)
{
var System = new Program();
System.HelloWorld();
Console.ReadLine();
}
public string HelloWorld()
{
Template template;
var path = @"C:\TemplateTester\index.st";
var file = new FileInfo(path);
using (StreamReader reader = file.OpenText())
template = new Template(reader.ReadToEnd(), '$', '$'); // custom delimeter (defaults are "<" and ">")
template.Add("title", "Hello World!");
template.Add("array", new string[] { "Record A", "Record B", "Record C" });
template.Add("object", new { PropertyA = "A", PropertyB = "B" });
return template.Render();
}
My ST file
<html>
<body>
<h1>Hello World</h1>
$! file: C:\TemplateTester\index.st !$
String:
$string$
Array:
$array:{it|$it$ ($i$)};separator=", "$
Object:
Property A = $object.PropertyA$
Property B = $object.PropertyB$
</body>
</html>
I can't add a image of my FilePath due to my current reputation however, the ST file is just sitting within the Application folder as the path would suggest with the visual studio file. External from the Program Folder(containing bin, obj, properties etc) and Package folder(containing Antlr references).
The template file contains an expression $string$
, but you did not define the value for the string
attribute using the template.Add
method like you did for title
, array
, and object
.