/// <summary> /// Set ordered view fields. /// </summary> /// <param name="fields">The ordered field names.</param> public void SetViewFields(params string[] fields) { var tmpFields = FieldRefs.ToList(); this.FieldRefs.Clear(); foreach (var field in fields) { var fieldRef = tmpFields.FirstOrDefault(e => e.Name.Equals(field)); if (fieldRef == null) { fieldRef = new ContentFieldRef(this, this.Parent.Fields[field]); } this.FieldRefs.Add(fieldRef); } this.Model.FieldRefsXml = FieldRefs.Element().OuterXml(); this.FieldRefsXml = this.Model.FieldRefsXml; Context.SaveChanges(); this.Refresh(); }
private static void RenderViewFieldTemplate(this HtmlHelper helper, ContentFieldRef field, string filePrefix, ContentQueryResultItem item) { var tmpl = field.Template; var list = field.Parent; var server = helper.ViewContext.RequestContext.HttpContext.Server; if (!string.IsNullOrEmpty(tmpl.Source)) { var viewFileName = list.Package.ResolveUri(field.Template.Source); if (File.Exists(server.MapPath(viewFileName))) helper.RenderPartial(viewFileName, new ContentViewFieldValue(field, item)); else { //Find template file in default path viewFileName = "~/content/types/base/fields/view/" + field.Template.Source; if (File.Exists(server.MapPath(viewFileName))) helper.RenderPartial(viewFileName, new ContentViewFieldValue(field, item)); else helper.ViewContext.Writer.Write("<span>Field template file not found.</span>"); } } else { if (!string.IsNullOrEmpty(tmpl.Text)) { var viewFile = string.Format("_view_{0}_field_{1}_tmpl.cshtml", field.ParentView.Name.ToLower(), field.Name.ToLower()); var viewUrl = TemplateHelper.SaveAsView(field.Parent, tmpl.Text, viewFile); helper.RenderPartial(viewUrl, new ContentViewFieldValue(field, item)); } } }
/// <summary> /// Set ordered view fields. /// </summary> /// <param name="fields">The ordered field names.</param> public void SetViewFields(params string[] fields) { var tmpFields = FieldRefs.ToList(); this.FieldRefs.Clear(); foreach (var field in fields) { var fieldRef = tmpFields.FirstOrDefault(e => e.Name.Equals(field)); if (fieldRef == null) fieldRef = new ContentFieldRef(this, this.Parent.Fields[field]); this.FieldRefs.Add(fieldRef); } this.Model.FieldRefsXml = FieldRefs.Element().OuterXml(); this.FieldRefsXml = this.Model.FieldRefsXml; Context.SaveChanges(); this.Refresh(); }
/// <summary> /// Initializes a new instance of the ContentViewFieldValue class with field and item. /// </summary> /// <param name="field">The view field object</param> /// <param name="item">The query result item.</param> public ContentViewFieldValue(ContentFieldRef field, ContentQueryResultItem item) { this.Item = item; Field = field; }