示例#1
0
        public void TestCompileFunction()
        {
            var            temp = @"
$lang(home) 
$navigator()
${archive.data(视频)}
     <div>
              $categories('prod\,uct',{
                    <div class=""col-md-3 col-lg-2 col-sm-4"">
                        {name}
                    </div>
        }) </div>
";
            IDataContainer dc   = new NormalDataContainer();
            TemplatePage   tp   = new TemplatePage(dc);

            tp.TemplateHandleObject = new TemplateMock();
            tp.OnPreInit           += TemplateMock.CompliedTemplate;
            tp.OnBeforeCompile     += (TemplatePage page, ref String content) =>
            {
                var pageArchive = new PageArchive(new ArchiveDto());
                page.AddVariable("archive", pageArchive);
            };
            tp.SetTemplateContent(temp);
            var content = tp.Compile();

            Console.WriteLine(content);
        }
示例#2
0
        public string GetArchive(ArchiveDto archive)
        {
            #region 属性

            /*
             * //验证密码
             * PropertyBLL pbll = new PropertyBLL();
             * var a = pbll.GetProperty(category.ModuleID, "pwd");
             * if (a != null)
             * {
             *  var json = archive.GetPropertiesJson();
             *  string key = json.GetValue("pwd");
             *  if (!String.IsNullOrEmpty(key))
             *  {
             *      string requireKey = HttpContext.Current.Request.QueryString["pwd"];
             *      if (requireKey != key)
             *      {
             *          HttpContext.Current.Response.Write("<div style='margin:0 auto;padding:30px 0'>请输入密码:<input type='text'/><input type='button' value='提交' onclick=\"location.replace(location.href+'?pwd='+this.previousSibling.value)\"/></div>");
             *          HttpContext.Current.Response.End();
             *      }
             *
             *  }
             * }*/

            #endregion

            //获取模板ID
            var tplId    = GetArchiveTemplateId(archive);
            var category = archive.Category;

            //用于当前的模板共享数据
            Cms.Context.Items["archive.id"]    = archive.Id;
            Cms.Context.Items["category.path"] = category.Path;
            Cms.Context.Items["module.id"]     = category.ModuleId;


            //解析模板
            var html = PageUtility.Require(tplId,
                                           page =>
            {
                page.AddVariable("site", _site);

                var pageArchive = new PageArchive(archive);

                page.AddVariable("archive", pageArchive);

                page.AddVariable("category", category);
                page.AddVariable("module", new Module {
                    ID = category.ModuleId
                });


                page.AddVariable("page", new PageVariable
                {
                    Title       = $"{archive.Title}_{category.Name}_{_site.Title}",
                    SubTitle    = _site.Title,
                    Keywords    = archive.Tags,
                    Description = pageArchive.Outline.Replace("\"", string.Empty)
                });
            });
            return(html);
        }