Exemplo n.º 1
0
        public MvcLink(ViewContext viewContext, ILinkFieldRenderingString linkField, string alternateTag)
        {
            this.viewContext = viewContext;

            if (linkField?.Url != null)
            {
                // link given - render an anchor tag
                this.tagBuilder = new TagBuilder("a");
                this.tagBuilder.Attributes.Add("href", linkField.Url);
                // add optional attributes
                if (!string.IsNullOrWhiteSpace(linkField.Target))
                {
                    this.tagBuilder.Attributes.Add("target", linkField.Target);
                }
                if (!string.IsNullOrWhiteSpace(linkField.Class))
                {
                    this.tagBuilder.Attributes.Add("class", linkField.Class);
                }
                if (!string.IsNullOrWhiteSpace(linkField.Description))
                {
                    this.tagBuilder.Attributes.Add("title", linkField.Description);
                }
            }
            else if (string.IsNullOrWhiteSpace(alternateTag))
            {
                // no link given - render the alternate tag if provided
                this.tagBuilder = new TagBuilder(alternateTag);
            }

            // render the opening tag
            if (this.tagBuilder != null)
            {
                viewContext.Writer.Write(this.tagBuilder.ToString(TagRenderMode.StartTag));
            }
        }
Exemplo n.º 2
0
 public static IDisposable BeginLink(this HtmlHelper htmlHelper, ILinkFieldRenderingString linkField, string alternateTag = null, bool skipInPageEditor = false)
 {
     if (skipInPageEditor && global::Sitecore.Context.PageMode.IsExperienceEditor)
     {
         return(new EmptyMvcLink());
     }
     return(new MvcLink(htmlHelper.ViewContext, linkField, alternateTag));
 }