/// <summary> /// 获取聚合区块对应的 BinderController。加载模板的时候,检查是否已经自定义了模板。 /// </summary> /// <param name="section"></param> /// <param name="ctx"></param> /// <returns></returns> public static ISectionBinder GetBinder(ContentSection section, MvcContext ctx) { IContentSectionTemplateService TplService = ObjectContext.Create <IContentSectionTemplateService>(typeof(ContentSectionTemplateService)); ContentSectionTemplate template = TplService.GetById(section.TemplateId); String binderName = string.Format("wojilu.Web.Controller.Content.Binder.{0}BinderController", template.TemplateName); ControllerBase controller = ControllerFactory.FindController(binderName, ctx) as ControllerBase; if (controller == null) { throw new Exception("ISectionBinder not found:" + binderName); } String customTemplateStr = getCustomTemplateBody(section, ctx); // 自定义模板 if (strUtil.HasText(customTemplateStr)) { controller.viewContent(customTemplateStr); return(controller as ISectionBinder); } else { Template currentView = controller.utils.getTemplateByFileName(BinderUtils.GetBinderTemplatePath(template)); controller.utils.setCurrentView(currentView); return(controller as ISectionBinder); } }
public static void bindListItem(IBlock block, ContentPost post, MvcContext ctx) { if (post.PageSection != null) { block.Set("post.SectionName", post.PageSection.Title); block.Set("post.SectionUrl", clink.toSection(post.PageSection.Id, ctx)); } IPageAdminSection sectionController = BinderUtils.GetPageSectionAdmin(post, ctx, "AdminSectionShow"); String typeIcon = sectionController.GetSectionIcon(post.SectionId); block.Set("post.ImgIcon", typeIcon); String att = post.Attachments > 0 ? "<img src=\"" + strUtil.Join(sys.Path.Img, "attachment.gif") + "\"/>" : ""; block.Set("post.AttachmentIcon", att); block.Set("post.TitleCss", post.Style); block.Set("post.Title", strUtil.SubString(post.GetTitle(), 50)); block.Set("post.Created", post.Created.ToString("yyyy-MM-dd HH:mm:ss")); block.Set("post.Hits", post.Hits); block.Set("post.Url", alink.ToAppData(post, ctx)); if (post.Creator != null) { block.Set("post.Submitter", string.Format("<a href=\"{0}\" target=\"_blank\">{1}</a>", Link.ToMember(post.Creator), post.Creator.Name)); } else { block.Set("post.Submitter", ""); } }
public static String getServiceTemplates(String filterString, String tpl, MvcContext ctx, IContentSectionTemplateService templateService) { String thumbPath = BinderUtils.GetBinderTemplateThumbPath(); StringBuilder builder = new StringBuilder(); builder.Append("<table style=\"width: 100%\" cellpadding='5'><tr>"); List <ContentSectionTemplate> templates = templateService.GetBy(filterString); if (ctx.owner.obj is Site) { templates = TemplateUtil.addJson(templates); } int icount = 0; foreach (ContentSectionTemplate template in templates) { builder.AppendFormat("<td style=\"vertical-align:top;\"><label for=\"template{0}\"><img src='{1}{2}.png' style='width:150px;height:100px;' /></label><br/>", template.Id, thumbPath, template.TemplateName); builder.AppendFormat("<input name=\"templateId\" id=\"template{0}\" type=\"radio\" value=\"{0}\"", template.Id); if (tpl.Equals(template.TemplateName)) { builder.Append(" checked "); } builder.AppendFormat("/><label for=\"template{0}\">{1}</label></td>", template.Id, template.Name); if ((icount % 4) == 3) { builder.Append("</tr><tr>"); } icount++; } builder.Append("</table>"); return(builder.ToString()); }