public static HtmlString Edit <TBase, TProp>(this SitecoreHelper sitecoreHelper, TBase itemBase, Expression <Func <TBase, TProp> > property, object parameters = null) where TBase : ItemBase { var type = typeof(TBase); var member = property.Body as MemberExpression; if (member == null) { return(null); } var propInfo = member.Member as PropertyInfo; if (propInfo == null) { var func = property.Compile(); return(new HtmlString(func(itemBase).ToString())); } if (type != propInfo.ReflectedType && !type.IsSubclassOf(propInfo.ReflectedType)) { throw new ArgumentException( $"Expression '{property}' refers to a property that is not from type {type.FullName}."); } return(sitecoreHelper.Field(propInfo.Name, itemBase.Item, parameters)); }
public static HtmlString Field(this SitecoreHelper helper, ID fieldID, Item item, object parameters) { Assert.ArgumentNotNullOrEmpty(fieldID, nameof(fieldID)); Assert.IsNotNull(item, nameof(item)); Assert.IsNotNull(parameters, nameof(parameters)); return(helper.Field(fieldID.ToString(), item, parameters)); }
public HtmlString Field(string fieldName) { var scHtml = _sitecoreHelper.Field(fieldName); var jsV = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(scHtml.ToHtmlString())); return(new HtmlString(string.Format(_script, fieldName.Replace(' ', '_'), jsV))); }
public static HtmlString FormattedDateTimeField(this SitecoreHelper sitecoreHelper, Item item, string fieldName, string format) { if (Sitecore.Context.PageMode.IsExperienceEditor) { return(sitecoreHelper.Field(fieldName, item)); } return(new HtmlString(DateTimeField(sitecoreHelper, item, fieldName).ToString(format))); }
public static HtmlString DictionaryField(this SitecoreHelper helper, string relativePath, string defaultValue = "") { var item = DictionaryPhraseRepository.Current.GetItem(relativePath, defaultValue); if (item == null) { return(new HtmlString(defaultValue)); } return(helper.Field(Templates.DictionaryEntry.Fields.Phrase, item)); }
private HtmlString RenderField(Item contextItem, ViewPart viewPart) { var fieldName = viewPart["Name"]; if (!string.IsNullOrEmpty(fieldName)) { var fieldHtml = string.IsNullOrEmpty(viewPart.CssClass) && string.IsNullOrEmpty(viewPart.Style) ? _scHelper.Field(fieldName, contextItem) : _scHelper.Field(fieldName, contextItem, new { @class = viewPart.CssClass, style = viewPart.Style }); if (!string.IsNullOrEmpty(viewPart.TagWrapper)) fieldHtml = fieldHtml.WrapWithTag(viewPart.TagWrapper); return fieldHtml; } return new HtmlString(string.Empty); }
public static HtmlString ImageField(this SitecoreHelper helper, string fieldName, Item item, int mh = 0, int mw = 0, string cssClass = null, bool disableWebEditing = false) { return(helper.Field(fieldName, item, new { mh, mw, DisableWebEdit = disableWebEditing, @class = cssClass ?? "" })); }
public static HtmlString ImageField(this SitecoreHelper helper, ID fieldID, Item item, int mh = 0, int mw = 0, string cssClass = null, bool disableWebEditing = false) { return(helper.Field(fieldID.ToString(), item, new { mh, mw, DisableWebEdit = disableWebEditing, @class = cssClass ?? string.Empty })); }
public void DictionaryField_TranslationItemExists_ReturnFieldRenderer(string path, string defaultValue, Item translateItem, [Substitute] SitecoreHelper sitecoreHelper) { //Arrange this.dictionaryPhraseRepository.GetItem(path, defaultValue).Returns(x => translateItem); sitecoreHelper.Field(Arg.Any <string>(), Arg.Any <Item>()).Returns(x => new HtmlString($"fieldId:{x.Arg<string>()} itemId:{x.Arg<Item>().ID}")); //Act var result = SitecoreExtensions.DictionaryField(sitecoreHelper, path, defaultValue); //Assert result.ToHtmlString().Should().Be($"fieldId:{{DDACDD55-5B08-405F-9E58-04F09AED640A}} itemId:{translateItem.ID}"); }
public static HtmlString RenderField(this SitecoreHelper sitecoreHelper, string fieldNameOrId, Item item, bool disableWebEdit = false, SafeDictionary <string> parameters = null) { if (parameters == null) { parameters = new SafeDictionary <string>(); } return(sitecoreHelper.Field(fieldNameOrId, new { DisableWebEdit = disableWebEdit, Parameters = parameters })); }
public static HtmlString RenderResponsivePicture(this SitecoreHelper helper, string fieldName, Item item = null, bool isEditable = false, List <Dimensions> dimensions = null) { if (item.Fields[fieldName] == null) { return(new HtmlString(string.Empty)); } var mediaItem = new ImageField(item.Fields[fieldName]).MediaItem; if (mediaItem == null) { return(new HtmlString(string.Empty)); } if (Sitecore.Context.PageMode.IsExperienceEditor) { return(helper.Field(fieldName, item)); } return(GeneratePictureTag(dimensions, mediaItem)); }
private static HtmlTag ApplyFieldSyntax(SitecoreHelper helper, HtmlTag tag) { tag.Text = DoInterpolate(tag.Text); tag.Attributes = tag.Attributes?.ToDictionary(kv => kv.Key, kv => DoInterpolate(kv.Value)); return(tag); string DoInterpolate(string text) { if (string.IsNullOrEmpty(text)) { return(text); } var matches = FieldRegex.Matches(text); foreach (Match match in matches) { var fieldName = match.Groups["fieldName"].Value; if (string.IsNullOrWhiteSpace(fieldName)) { continue; } var parameters = ParseParameters(match.Groups["parameters"].Value); var fromPage = MainUtil.GetBool(parameters["fromPage"], false); var rawValue = MainUtil.GetBool(parameters["raw"], false); var source = ResolveSource(fieldName, fromPage); if (rawValue) { text = text.Replace(match.Value, source.item[source.field]); } else { var editable = MainUtil.GetBool(parameters["editable"], true); var field = helper.Field(source.field, source.item, new { DisableWebEdit = !editable }).ToString(); text = text.Replace(match.Value, field); } } return(text); } (string field, Item item) ResolveSource(string text, bool fromPage) { var item = fromPage ? RenderingContext.Current.PageContext.Item : RenderingContext.Current.Rendering.Item; var sourceNames = text?.Split('.')?.ToList(); if (sourceNames == null || !sourceNames.Any()) { return(text, item); } var fieldName = sourceNames.Last(); var source = sourceNames.GetRange(0, sourceNames.Count - 1).Aggregate(item, GetTargetItem); return(source == null ? (text, item) : (fieldName, source)); } Item GetTargetItem(Item item, string fieldName) { return(((LinkField)item?.Fields[fieldName])?.TargetItem ?? ((ReferenceField)item?.Fields[fieldName])?.TargetItem); } }
public static HtmlString ImageField(this SitecoreHelper helper, string fieldName, Item item, int mh, int mw, bool disableWebEditing = false) { return(helper.Field(fieldName, item, new { mh, mw, DisableWebEdit = disableWebEditing })); }
public static HtmlString Field(this SitecoreHelper helper, ID fieldID) { Assert.ArgumentNotNullOrEmpty(fieldID, nameof(fieldID)); return(helper.Field(fieldID.ToString())); }
public static HtmlString LinkField(this SitecoreHelper helper, string fieldName, string text, bool disableWebEdit = false) { return(helper.Field(fieldName, new { text, DisableWebEdit = disableWebEdit })); }
public static HtmlString Field(this SitecoreHelper helper, ID fieldID, Item item) { return(helper.Field(fieldID.ToString(), item)); }
public static HtmlString Field(this SitecoreHelper helper, ID fieldID, object parameters) { return(helper.Field(fieldID.ToString(), parameters)); }