By default, tags are delimited by {%, /}, {$ and %}; expressions are delimited by '$': $ ... $; comments are delimited by {! and !}; This is good for the most common case of HTML generation. Sometimes, you may want to change the delimiters to avoid conflict with other formats like SQL statement generation. You can change the delimiters by setting BeginChar, EndChar, CommentChar and BeginEndExpressionChar in TemplateEngineSettings class.
The following example shows you how to change these delimiters in ComponentSoft Template Engine:
Template.tpl Copy Code
<%float f = 10.2f/> <# Initializes variable f #>
$f$ <# Prints out the variable f #>
The output will be:
10.2
C# Copy Code
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using ComponentSoft;
namespace CSharp
{
public class ChangeDelimiterCharacters
{
[STAThread]
static void Main()
{
TemplateEngine dt = new TemplateEngine();
dt.Settings.BeginChar = '<';
dt.Settings.EndChar = '>';
dt.Settings.CommentChar = '#';
dt.Settings.BeginEndExpressionChar = '$';
dt.LoadFromFile("Template.tpl");
string output = dt.Run();
Console.WriteLine(output);
}
}
}
VB.NET Copy Code
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Collections
Imports ComponentSoft
Module ChangeDelimiterCharacters
Sub Main()
Dim dt As New TemplateEngine()
dt.Settings.BeginChar = "<"
dt.Settings.EndChar = ">"
dt.Settings.CommentChar = "#"
dt.Settings.BeginEndExpressionChar = "@"
dt.LoadFromFile("Template.tpl")
Dim output As String = dt.Run()
Console.WriteLine(output)
End Sub
End Module
No comments:
Post a Comment