public TemplateRenderModel(Template template) { Id = template.Id; Name = template.Name; CacheName = TemplateServices.GetTemplateCacheName(template.Name, template.Created, template.Updated); Content = template.Content; }
/// <summary> /// Check if template is modified to re-cache /// </summary> /// <param name="virtualPath"></param> /// <param name="virtualPathDependencies"></param> /// <returns></returns> public override string GetFileHash(string virtualPath, System.Collections.IEnumerable virtualPathDependencies) { if (IsPathIsDbTemplate(virtualPath)) { var template = FindTemplate(virtualPath); return(TemplateServices.GetTemplateCacheName(template.Name, template.Created, template.Updated)); } return(base.GetFileHash(virtualPath, virtualPathDependencies)); }
public string RenderPageTemplate(int?pageTemplateId, PageRenderModel model) { var pageTemplate = GetById(pageTemplateId); var config = _templateServices.GetConfig(); using (var templateService = new TemplateService(config)) { /* * Get default master template for all content * This template is used for including some scripts or html for all page contents and file contents */ var defaultTemplate = GetDefaultTemplate(); var template = defaultTemplate.Content; template = CurlyBracketParser.ParseProperties(template); template = CurlyBracketParser.ParseRenderBody(template); var layout = TemplateServices.GetTemplateCacheName(defaultTemplate.Name, defaultTemplate.Created, defaultTemplate.Updated); if (Razor.Resolve(layout) == null) { templateService.Compile(template, typeof(PageRenderModel), layout); } /* * Loop all the parent template to compile and render layout */ if (pageTemplate != null) { // Using hierarchy to load all parent templates var pageTemplates = _pageTemplateRepository.GetAll().Where(t => pageTemplate.Hierarchy.Contains(t.Hierarchy)) .OrderBy(t => t.Hierarchy) .Select(t => new { t.Content, t.Name, t.Updated, t.Created }); if (pageTemplates.Any()) { foreach (var item in pageTemplates) { //Convert curly bracket properties to razor syntax template = CurlyBracketParser.ParseProperties(item.Content); //Insert master page for child template and parsing template = InsertMasterPage(template, layout); template = FormatMaster(template); template = templateService.Parse(template, model, null, null); template = ReformatMaster(template); //This used for re-cache the template layout = TemplateServices.GetTemplateCacheName(item.Name, item.Created, item.Updated); //Convert {RenderBody} to @RenderBody() for next rendering template = CurlyBracketParser.ParseRenderBody(template); if (Razor.Resolve(layout) == null) { templateService.Compile(template, typeof(PageRenderModel), layout); } } } } return(template); } }