欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

SharpTAL 使用的示例代码,sharptal示例代码,SharpTAL 将基于

来源: javaer 分享于  点击 24100 次 点评:193

SharpTAL 使用的示例代码,sharptal示例代码,SharpTAL 将基于


SharpTAL 将基于 XML 的模板编译成 .NET 的编译代码,包含对 Zope Page Templates (ZPT) 语言的完整实现。

using System;using System.IO;using System.Reflection;using System.Collections.Generic;using SharpTAL;namespace Demo{    class Demo    {        static void Main(string[] args)        {            // Set path to the existing cache folder            string cacheFolder = Path.Combine(Path.GetDirectoryName(                Assembly.GetExecutingAssembly().Location), "Template Cache");            // Create the template cache.            // We want to clear the cache folder on startup, setting the clearCache parameter to true,            // and using customized file name pattern.            FileSystemTemplateCache cache =                 new FileSystemTemplateCache(cacheFolder, true, @"Demo_{key}.dll");            // The body of the template            string templateBody = @"<html><h1 tal:content=""title"">The title goes here</h1></html>";            // Global variables used in template            Dictionary<string, object> globals = new Dictionary<string, object>();            globals["title"] = "Hello World !";            // Finally, render the template. In this moment the assembly will be generated and cached            string slowResult = cache.RenderTemplate(templateBody, globals);            // The "slowResult" will contain: <html><h1>Hello World !</h1></html>            // Set the title to another value            globals["title"] = "Hi !";            // A second call to RenderRemplate() will use cached assembly            string fastResult = cache.RenderTemplate(templateBody, globals);            // The "fastResult" will contain: <html><h1>Hi !</h1></html>        }    }}//该片段来自于http://byrx.net
相关栏目:

用户点评