private static Link CreateLink(HrefLink source, RenderContext ctx) { var link = new Link(); link.CopyFrom(source); link.Href = UriUtil.ApplyUriTemplate(link.Href, ctx.HttpContext); return(link); }
public static MvcHtmlString PageLinkWithBreadcrum(this HtmlHelper html, IPage page) { var url = new UrlHelper(html.ViewContext.RequestContext); StringBuilder sb = new StringBuilder(); List <HrefLink> breadcrumb = new List <HrefLink>(); if (page.NaviNode != null && page.NaviNode.Id != 1) { NaviNode naviNode = page.NaviNode; int loop = 0; while (naviNode != null && naviNode.Id != 1) { HrefLink link = new HrefLink(); link.Text = System.Web.HttpUtility.HtmlEncode(naviNode.NodeName); link.Title = System.Web.HttpUtility.HtmlEncode(naviNode.NodeName); link.Url = linkForNode(naviNode, url); breadcrumb.Insert(0, link); naviNode = naviNode.Parent; loop++; if (loop > 100) { throw new Exception("Invalid Navigation"); } } } foreach (HrefLink node in breadcrumb) { if (node.Url != "#") { sb.Append(node.Text); } else { sb.Append(node.Text); } sb.Append(" // "); } return(MvcHtmlString.Create(sb.ToString())); }
public static MvcHtmlString ActionBreadcrumb(this HtmlHelper html, IPage page) { var url = new UrlHelper(html.ViewContext.RequestContext); StringBuilder sb = new StringBuilder(); List <HrefLink> breadcrumb = new List <HrefLink>(); if (page.NaviNode != null && page.NaviNode.Id != 1) { NaviNode naviNode = page.NaviNode; int loop = 0; while (naviNode != null) { HrefLink link = new HrefLink(); link.Text = System.Web.HttpUtility.HtmlEncode(naviNode.NodeName); link.Title = System.Web.HttpUtility.HtmlEncode(naviNode.NodeName); link.Url = linkForNode(naviNode, url); breadcrumb.Insert(0, link); naviNode = naviNode.Parent; loop++; if (loop > 100) { throw new Exception("Invalid Navigation"); } } } foreach (HrefLink node in breadcrumb) { if (node.Url != "#") { var anchorBuilder = new TagBuilder("a"); anchorBuilder.MergeAttribute("href", node.Url); //anchorBuilder.MergeAttribute("title", node.Title); //anchorBuilder.MergeAttribute("alt", node.Title); anchorBuilder.InnerHtml = node.Text; sb.Append(anchorBuilder.ToString(TagRenderMode.Normal)); } else { sb.Append(node.Text); } sb.Append(" // "); } sb.Append(page.NaviTitle == null ? page.Title : page.NaviTitle); return(MvcHtmlString.Create(sb.ToString())); }
public static MvcHtmlString ActionBreadcrumbCms(this HtmlHelper html, NaviNode naviNode, string action, string controller) { var url = new UrlHelper(html.ViewContext.RequestContext); StringBuilder sb = new StringBuilder(); List <HrefLink> breadcrumb = new List <HrefLink>(); NaviNode currentNode = naviNode.Parent; int loop = 0; while (currentNode != null) { HrefLink link = new HrefLink(); link.Text = System.Web.HttpUtility.HtmlEncode(currentNode.NodeName); link.Title = System.Web.HttpUtility.HtmlEncode(currentNode.NodeName); if (action == null) { link.Url = null; } else { link.Url = url.Action(action, controller, new { id = currentNode.Id }); } breadcrumb.Insert(0, link); currentNode = currentNode.Parent; loop++; if (loop > 100) { throw new Exception("Invalid Navigation"); } } foreach (HrefLink node in breadcrumb) { if (node.Url == null) { sb.Append(node.Text); } else { var anchorBuilder = new TagBuilder("a"); anchorBuilder.MergeAttribute("href", node.Url); anchorBuilder.MergeAttribute("title", node.Title); anchorBuilder.MergeAttribute("alt", node.Title); anchorBuilder.InnerHtml = node.Text; sb.Append(anchorBuilder.ToString(TagRenderMode.Normal)); } sb.Append(" // "); } sb.Append(naviNode.NodeName); /* * sb.Append(@"<div id=""titleContainer""> * <div id=""title""> * <div id=""metaTitle""> * <div style=""position: relative""> * <div id=""C-Title"">"); * * sb.Append(naviNode.NodeName); * * sb.Append(@"</div> * <img width=""13"" height=""11"" alt=""more"" src=""Styles/details/dropArrow.png"" id=""titleDropdown"" * style=""display: inline;""> * </div> * </div> * <div id=""moreTitles"" style=""display: none;"">"; * * sb.Append("<div>"); * sb.Append(naviNode.NodeName); * sb.Append("</div>"); * * * sb.Append(@"</div> * </div> * </div>"); */ return(MvcHtmlString.Create(sb.ToString())); }
private static string BuildContent(IPage page) { var n = page.NaviNode; var sb = new StringBuilder(); sb.Append("<div data-replace=\"[$webpart(breadcrumb)$]\" class=\"cms-replaceable breadcrumbWrapper\">"); List <HrefLink> breadcrumb = new List <HrefLink>(); if (n != null)// && n.Id != 1) { NaviNode naviNode = n; int loop = 0; while (naviNode != null) { HrefLink link = new HrefLink(); link.Text = HttpUtility.HtmlEncode(naviNode.NodeName); link.Title = HttpUtility.HtmlEncode(naviNode.NodeName); var subpages = naviNode.Pages; if (subpages != null && subpages.Count > 0) { var defaultPage = subpages.OrderBy(e => e.MenuOrder).First(); link.Url = "/" + defaultPage.Url; } else { link.Url = "#"; } breadcrumb.Insert(0, link); naviNode = naviNode.Parent; loop++; if (loop > 100) { throw new Exception("Invalid Navigation"); } } } foreach (HrefLink node in breadcrumb) { if (node.Url != "#") { var anchorBuilder = new TagBuilder("a"); anchorBuilder.MergeAttribute("href", node.Url); //anchorBuilder.MergeAttribute("title", node.Title); //anchorBuilder.MergeAttribute("alt", node.Title); anchorBuilder.InnerHtml = node.Text; sb.Append(anchorBuilder.ToString(TagRenderMode.Normal)); } else { sb.Append(node.Text); } sb.Append("<span class='breadcrumb-arrow'></span>"); } if (page == null) { sb.Append("[Navi Title]"); } else { sb.Append(page.NaviTitle == null ? page.Title : page.NaviTitle); } sb.Append("</div>"); return(sb.ToString()); }