当前位置: 首页>>代码示例>>C#>>正文


C# IContent.GetReferenceTree方法代码示例

本文整理汇总了C#中IContent.GetReferenceTree方法的典型用法代码示例。如果您正苦于以下问题:C# IContent.GetReferenceTree方法的具体用法?C# IContent.GetReferenceTree怎么用?C# IContent.GetReferenceTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IContent的用法示例。


在下文中一共展示了IContent.GetReferenceTree方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RenderBlockBreadcrumbs

        public static void RenderBlockBreadcrumbs(this HtmlHelper htmlHelper, IContent currentBlock)
        {
            var repo = ServiceLocator.Current.GetInstance<IContentRepository>();
            var urlHelper = ServiceLocator.Current.GetInstance<UrlHelper>();
            var writer = htmlHelper.ViewContext.Writer;

            int topLevelNumberOfReferences;
            var usages = currentBlock.GetReferenceTree(repo, out topLevelNumberOfReferences).ToList();

            if (!usages.Any() && topLevelNumberOfReferences <= 1)
            {
                writer.Write("<div class=\"{0}-item\">" +
                             "<span class=\"{0}-title\">This block has no usages yet</span><div>" +
                             "<a class=\"{0}-usage {0}-usage--multiple\" href=\"\"></a>" +
                             "</div></div>",
                    CssNamespace);
                return;
            }

            var highlights = usages.Concat(new[] { currentBlock }).GetEnumerator();
            highlights.MoveNext();

            var breadCrumbWrapper = new TagBuilder("div");
            breadCrumbWrapper.AddCssClass(CssNamespace);

            writer.Write(breadCrumbWrapper.ToString(TagRenderMode.StartTag));

            if (topLevelNumberOfReferences > 1)
            {
                writer.Write("<div class=\"{0}-item\">" +
                             "<span class=\"{0}-title\" title=\"{1} usages...\">{1} usages...</span><div>" +
                             "<a class=\"{0}-usage {0}-usage--multiple\">...</a>" +
                             "<span class=\"{0}-arrow\">❯</span></div></div>",
                    CssNamespace,
                    topLevelNumberOfReferences);
            }
            foreach (var usage in usages)
            {
                highlights.MoveNext();
                var url = urlHelper.ContentUrl(usage.ContentLink);

                var html = string.Format("<div class=\"{0}-item {1}\">" +
                                         "<span class=\"{0}-title\" title=\"{2}\">{2}</span><div>" +
                                         "<a href=\"{3}\" class=\"{0}-usage\">" +
                                         "<iframe src=\"{4}\" width=\"1170\" height=\"1170\" scrolling=\"no\"></iframe>" +
                                         "</a><span class=\"{0}-arrow\">❯</span></div></div>",
                    CssNamespace
                    , usage.IsPublished() ? "" : string.Format("{0}-pending", CssNamespace)
                    , usage.Name
                    , url
                    , url.AddQueryParameter(Constants.HighlightQueryStringKey, highlights.Current.ContentGuid.ToString()));

                writer.Write(html);
            }

            writer.Write("<div class=\"{0}-item\"><span class=\"{0}-title {0}-this\">This block</span></div>", CssNamespace);
            writer.Write(breadCrumbWrapper.ToString(TagRenderMode.EndTag));
        }
开发者ID:prokom-no,项目名称:block-breadcrumbs,代码行数:58,代码来源:BreadcrumbHelper.cs


注:本文中的IContent.GetReferenceTree方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。