public NewsPromoSectionViewModel GetNewsPromos() { var contextItem = RenderingContext.Current.Rendering.Item; var vm = new NewsPromoSectionViewModel(); vm.Title = contextItem[Templates.ExpertAdviceGroup.Fields.Title]; LinkField lnk = contextItem.Fields[Templates.ExpertAdviceGroup.Fields.ListPage]; vm.DetailsPage.Text = lnk.Text; vm.DetailsPage.Url = lnk.GetFriendlyUrl(); var articleIds = contextItem[Templates.ExpertAdviceGroup.Fields.Articles]?.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (var articleId in articleIds) { try { var article = context.Database.GetItem(articleId); if (article != null) { var model = new NewsListModel(article); vm.Articles.Add(model); } } catch (Exception) { // TODO: Log error } } return(vm); }
private NavigationItemModel GetNavLink(Item navItem) { var model = new NavigationItemModel { Title = navItem["Navigation Item Title"], Url = "#", Children = new NavigationItemModel[0], }; if (!navItem.HasChildren) { LinkField lf = navItem.Fields["Navigation Item Link"]; if (!string.IsNullOrEmpty(lf?.GetFriendlyUrl())) { model.Url = lf.GetFriendlyUrl(); } } else { // The model supports endless recursion. The front end view, however, does not. var childNavItems = new List <NavigationItemModel>(); foreach (Item childNavItem in navItem.GetChildren()) { childNavItems.Add(GetNavLink(childNavItem)); } model.Children = childNavItems.ToArray(); } return(model); }
public virtual TopNavigationModel GetModel(Item actionItem) { var model = new TopNavigationModel { BrandLinkText = actionItem["Brand Link Text"], BrandLinkUrl = "/", }; LinkField lf = actionItem.Fields["Brand Link"]; if (!string.IsNullOrEmpty(lf?.GetFriendlyUrl())) { model.BrandLinkUrl = lf.GetFriendlyUrl(); } var navLinks = new List <NavigationItemModel>(); foreach (Item navLinkItem in actionItem.GetChildren()) { navLinks.Add(GetNavLink(navLinkItem)); } model.TopNavigationLinks = navLinks.ToArray(); return(model); }
public static string SafeLinkFieldFriendlyUrl(this Item item, ID fieldId) { var toReturn = string.Empty; if (item != null && !fieldId.IsNull) { LinkField linkField = item.Fields[fieldId]; if (linkField != null) { toReturn = linkField.GetFriendlyUrl(); } } else { if (item == null) { GatedContentLogger.Error("item is null", new object()); } if (fieldId.IsNull) { GatedContentLogger.Error("fieldId is null", new object()); } } return(toReturn); }
protected virtual string GetResourceUrl(LinkField linkField) { if (linkField == null || string.IsNullOrWhiteSpace(linkField.Value)) { return(null); } return(linkField.GetFriendlyUrl()); }
/// <inheritdoc /> protected override object GetValueToAssign() { LinkField linkField = Field; if (linkField.IsInternal) { return(linkField.GetFriendlyUrl()); } return(linkField.Url); }
public static string LinkFieldUrl(this Item item, ID fieldId) { if (item == null) { throw new ArgumentNullException(nameof(item)); } if (ID.IsNullOrEmpty(fieldId)) { throw new ArgumentNullException(nameof(fieldId)); } var field = item.Fields[fieldId]; if (field == null || !(FieldTypeManager.GetField(field) is LinkField)) { return(string.Empty); } LinkField linkField = field; switch (linkField.LinkType.ToLower()) { case "internal": // Use LinkMananger for internal links, if link is not empty //return linkField.TargetItem != null ? LinkManager.GetItemUrl(linkField.TargetItem) : string.Empty; return(linkField.TargetItem != null?linkField.GetFriendlyUrl() : string.Empty); case "media": // Use MediaManager for media links, if link is not empty return(linkField.TargetItem != null?MediaManager.GetMediaUrl(linkField.TargetItem) : string.Empty); case "external": // Just return external links return(linkField.Url); case "anchor": // Prefix anchor link with # if link if not empty return(!string.IsNullOrEmpty(linkField.Anchor) ? "#" + linkField.Anchor : string.Empty); case "mailto": // Just return mailto link return(linkField.Url); case "javascript": // Just return javascript return(linkField.Url); default: // Just please the compiler, this // condition will never be met return(linkField.Url); } }
private object TransformMenuItem(Item i) { if (i.Template.Key == "simple item") { var navigationItem = i.Database.GetItem(i["Item"]); if (navigationItem == null || navigationItem["Hide from Navigation"] == "1") { return(null); } return(new { Text = navigationItem["navigation title"], Link = LinkManager.GetItemUrl(navigationItem), Class = IsCurrent(navigationItem) ? "current" : "" }); } LinkField link = i.Fields["Link"]; return(new { Text = link.Text, Link = link.GetFriendlyUrl(), Class = "" }); }
public List <NavigationMenuItem> GetChildren(Item currentchildren) { List <NavigationMenuItem> Chill = new List <NavigationMenuItem>(); foreach (Item itemChill in currentchildren.Children) { var title = itemChill.Fields["Title"].Value; LinkField linkfield = itemChill.Fields["Destination"]; var url = linkfield.GetFriendlyUrl(); Chill.Add(new NavigationMenuItem { item = itemChill, Title = title, URL = url }); } return(Chill); }
protected virtual CallToActionModel GetModel(Item actionItem) { var model = new CallToActionModel { Text = RenderField(actionItem, "Call to Action Text"), ButtonText = actionItem["Call to Action Button Text"], }; LinkField lf = actionItem.Fields["Call to Action Link"]; if (!string.IsNullOrEmpty(lf?.GetFriendlyUrl())) { model.ButtonUrl = lf.GetFriendlyUrl(); } else { model.ButtonUrl = "#"; } return(model); }
private MarketingIconModel GetMarketingIcon(Item marketingIconItem) { var m = new MarketingIconModel { Title = marketingIconItem["Marketing Icon Title"], Text = marketingIconItem["Marketing Icon Text"], LinkText = marketingIconItem["Marketing Icon Link Text"], }; LinkField lf = marketingIconItem.Fields["Marketing Icon Link"]; if (!string.IsNullOrEmpty(lf?.GetFriendlyUrl())) { m.TargetUrl = lf.GetFriendlyUrl(); } else { m.TargetUrl = "#"; } return(m); }
private PriceOptionModel GetPriceOption(Item childPriceOption) { var m = new PriceOptionModel { Heading = childPriceOption["Price Option Heading"], Price = childPriceOption["Price Option Price"], Byline = childPriceOption["Price Option Byline"], IsPrimary = childPriceOption["Price Option Is Primary"] == "1", Bullet1 = childPriceOption["Price Option Bullet 1"], Bullet2 = childPriceOption["Price Option Bullet 2"], Bullet3 = childPriceOption["Price Option Bullet 3"], SignUpText = childPriceOption["Price Option Sign Up Text"], SignUpUrl = "#", }; LinkField lf = childPriceOption.Fields["Price Option Sign Up Link"]; if (!string.IsNullOrEmpty(lf?.GetFriendlyUrl())) { m.SignUpUrl = lf.GetFriendlyUrl(); } return(m); }
public ActionResult Slider() { try { var dataSourceId = RenderingContext.CurrentOrNull.Rendering.DataSource; if (string.IsNullOrEmpty(dataSourceId)) { return(PartialView()); } var dataSource = Sitecore.Context.Database.GetItem(dataSourceId); if (dataSource == null || dataSource.Children.Count == 0) { return(PartialView()); } if (!dataSource.IsDerived(Templates.SliderFolder.ID)) { return(PartialView()); } List <ISliderItem> Items = new List <ISliderItem>(); foreach (var slide in dataSource.Children.ToList()) { if (slide.IsDerived(Templates.ImageSlider.ID)) { ImageSlider _imageSlider = new ImageSlider(); _imageSlider.Title = slide.Fields[Templates.ImageSlider.Fields.Title].Value; _imageSlider.Description = slide.Fields[Templates.ImageSlider.Fields.Description].Value; ImageField _image = (ImageField)slide.Fields[Templates.ImageSlider.Fields.Image]; if (_image != null && _image.MediaItem != null) { _imageSlider.ImageUrl = MediaManager.GetMediaUrl(_image.MediaItem); } LinkField _Link = (LinkField)slide.Fields[Templates.ImageSlider.Fields.Link]; if (_Link != null) { _imageSlider.LinkUrl = _Link.GetFriendlyUrl(); _imageSlider.LinkTarget = _Link.Target; _imageSlider.LinkText = _Link.Text; } Items.Add(_imageSlider); } else if (slide.IsDerived(Templates.VideoSlider.ID)) { VideoSlider _videoSlider = new VideoSlider(); _videoSlider.Title = slide.Fields[Templates.VideoSlider.Fields.Title].Value; _videoSlider.Description = slide.Fields[Templates.VideoSlider.Fields.Description].Value; LinkField _videoLink = (LinkField)slide.Fields[Templates.VideoSlider.Fields.Video]; if (_videoLink != null) { MediaItem video = Sitecore.Context.Database.GetItem(_videoLink.TargetID); string src = Sitecore.Resources.Media.MediaManager.GetMediaUrl(video); _videoSlider.VideoUrl = src.Split('.')[0]; } LinkField _Link = (LinkField)slide.Fields[Templates.VideoSlider.Fields.Link]; if (_Link != null) { _videoSlider.LinkUrl = _Link.GetFriendlyUrl(); _videoSlider.LinkTarget = _Link.Target; _videoSlider.LinkText = _Link.Text; } Items.Add(_videoSlider); } } return(PartialView(Items)); } catch (Exception ex) { } return(PartialView()); }
protected virtual string GetResourceUrl(LinkField linkField) { return(string.IsNullOrWhiteSpace(linkField?.Value) ? null : linkField.GetFriendlyUrl()); }
public override string Value(TokenDataCollection extraData) { LinkField f = TokenKeeper.CurrentKeeper.GetDatabase().GetItem(BackingId).Fields["Link"]; return(string.Format("<a href='{0}' target='{1}' class='{2}' title='{3}'>{4}</a>", f.GetFriendlyUrl(), f.Target, f.Class, f.Title, extraData["Link Text"])); }
/// <inheritdoc /> public FieldMapStatus Map(object modelInstance, Field field) { Model = modelInstance; Field = field; if (Property == null) { return(FieldMapStatus.NoProperty); } if (Property.GetCustomAttribute <DoNotMapAttribute>() != null) { return(FieldMapStatus.ExplicitIgnore); } if (Property.GetCustomAttribute <RawValueOnlyAttribute>() != null) { if (Property.IsHtml()) { Property.SetValue(Model, new HtmlString(Field.Value)); return(FieldMapStatus.Success); } Property.SetValue(Model, Field.Value); return(FieldMapStatus.Success); } var paramsAttribute = Property.GetCustomAttribute <FieldRendererParamsAttribute>(); if (paramsAttribute != null) { if (Property.IsHtml()) { Property.SetValue(Model, new HtmlString(FieldRenderer.Render(Field.Item, Field.Name, paramsAttribute.Params))); return(FieldMapStatus.Success); } Property.SetValue(Model, FieldRenderer.Render(Field.Item, Field.Name, paramsAttribute.Params)); return(FieldMapStatus.Success); } var urlAttribute = Property.GetCustomAttribute <RenderAsUrlAttribute>(); if (urlAttribute == null || urlAttribute.UseFieldRendererInEditor && Sitecore.Context.PageMode.IsExperienceEditorEditing) { if (Property.IsHtml()) { Property.SetValue(Model, new HtmlString(FieldRenderer.Render(Field.Item, Field.Name))); return(FieldMapStatus.Success); } Property.SetValue(Model, FieldRenderer.Render(Field.Item, Field.Name)); return(FieldMapStatus.Success); } LinkField linkField = Field; Property.SetValue(Model, linkField.GetFriendlyUrl()); // Sitecore API has all the tricks for getting specific URL types out of this field. return(FieldMapStatus.Success); }
public IEnterspeedProperty Convert(Item item, Field field, EnterspeedSiteInfo siteInfo, List <IEnterspeedFieldValueConverter> fieldValueConverters) { LinkField linkField = field; if (linkField == null) { return(null); } var properties = new Dictionary <string, IEnterspeedProperty>(); if (!string.IsNullOrEmpty(linkField.Target)) { properties.Add(PropertyTarget, new StringEnterspeedProperty(PropertyTarget, linkField.Target)); } if (!string.IsNullOrEmpty(linkField.Anchor)) { properties.Add(PropertyAnchor, new StringEnterspeedProperty(PropertyAnchor, linkField.Anchor)); } if (!string.IsNullOrEmpty(linkField.Text)) { properties.Add(PropertyText, new StringEnterspeedProperty(PropertyText, linkField.Text)); } if (!string.IsNullOrEmpty(linkField.Title)) { properties.Add(PropertyTitle, new StringEnterspeedProperty(PropertyTitle, linkField.Title)); } if (!string.IsNullOrEmpty(linkField.Class)) { properties.Add(PropertyClass, new StringEnterspeedProperty(PropertyClass, linkField.Class)); } string url = null; if (linkField.LinkType == "media") { url = _urlService.GetMediaUrl(linkField.TargetItem); } else if (linkField.LinkType == "internal") { url = _urlService.GetItemUrl(linkField.TargetItem); if (linkField.TargetItem != null) { properties.Add(PropertyTargetType, new StringEnterspeedProperty(PropertyTargetType, linkField.TargetItem.TemplateName)); properties.Add(PropertyTargetId, new StringEnterspeedProperty(PropertyTargetId, _enterspeedIdentityService.GetId(linkField.TargetItem))); } } else if (linkField.LinkType == "external" || linkField.LinkType == "anchor" || linkField.LinkType == "mailto" || linkField.LinkType == "javascript") { url = linkField.GetFriendlyUrl(); } if (!string.IsNullOrEmpty(url)) { properties.Add(PropertyUrl, new StringEnterspeedProperty(PropertyUrl, url)); } else { return(null); } return(new ObjectEnterspeedProperty(_fieldService.GetFieldName(field), properties)); }