Пример #1
0
        /// <summary>
        /// 从指定路径加载模板
        /// </summary>
        /// <param name="path">模板文件</param>
        /// <param name="ctx">模板上下文</param>
        /// <returns>ITemplate</returns>
        public static ITemplate LoadTemplate(string path, TemplateContext ctx)
        {
            ResourceInfo info = Runtime.Load(path, ctx.Charset);
            Template     template;

            if (info != null)
            {
                template             = new Template(ctx, info.Content);
                template.TemplateKey = info.FullPath;
                ctx.CurrentPath      = Runtime.GetDirectoryName(info.FullPath);
            }
            else
            {
                template = new Template(ctx, string.Empty);
            }
            return(template);
        }
Пример #2
0
        /// <summary>
        /// 从指定路径加载模板
        /// </summary>
        /// <param name="path">模板文件</param>
        /// <param name="ctx">模板上下文</param>
        /// <returns>ITemplate</returns>
        public static async Task <ITemplate> LoadTemplateAsync(string path, TemplateContext ctx = null)
        {
            if (ctx == null)
            {
                ctx = CreateContext();
            }
            ResourceInfo info = await Runtime.LoadAsync(path, ctx.Charset);

            Template template;

            if (info != null)
            {
                template             = new Template(ctx, info.Content);
                template.TemplateKey = info.FullPath;
                ctx.CurrentPath      = Runtime.GetDirectoryName(info.FullPath);
            }
            else
            {
                template = new Template(ctx, string.Empty);
            }
            return(template);
        }