Sunday, July 18, 2010

Including an external template file

In some specific cases, you need to include an external template file to the current context. It can be done by using usetemplate keyword and to render a previously loaded template you have to use rendertemplate keyword, as shown in the following example:
ExtTemplate.tpl Copy Code

{%string str = "Second template"/}

Second Template
Template.tpl Copy Code

{%usetemplate myext "ExtTemplate.tpl"/}

First Template

{%rendertemplate myext/}

The output will be:

First Template

Second Template
C# Copy Code
using System;
using System.Collections.Generic;
using System.Text;
using ComponentSoft;
namespace CSharp
{
public class Sample
{
[STAThread]
static void Main()
{
TemplateEngine dt = new TemplateEngine();
dt.LoadFromFile("Template.tpl");
string output = dt.Run();
Console.WriteLine(output);
}
}
}
VB.NET Copy Code
Imports ComponentSoft
Module Sample
Sub Main()
Dim dt As TemplateEngine = New TemplateEngine()
Dim output As String
dt.LoadFromFile("Template.tpl")
output = dt.Run()
Console.WriteLine(output)
End Sub
End Module

No comments:

Post a Comment