本文整理汇总了C#中IContentLoader.GetAncestors方法的典型用法代码示例。如果您正苦于以下问题:C# IContentLoader.GetAncestors方法的具体用法?C# IContentLoader.GetAncestors怎么用?C# IContentLoader.GetAncestors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContentLoader
的用法示例。
在下文中一共展示了IContentLoader.GetAncestors方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderMainNavigation
public static void RenderMainNavigation(this HtmlHelper html, PageReference rootLink = null,
ContentReference contentLink = null,
bool includeRoot = true, IContentLoader contentLoader = null)
{
contentLink = contentLink ?? html.ViewContext.RequestContext.GetContentLink();
rootLink = rootLink ?? ContentReference.StartPage;
var writer = html.ViewContext.Writer;
// top level
writer.WriteLine("<nav class=\"navbar navbar-inverse\">");
writer.WriteLine("<ul class=\"nav navbar-nav\">");
if (includeRoot)
{
if (rootLink.CompareToIgnoreWorkID(contentLink))
{
writer.WriteLine("<li class=\"active\">");
}
else
{
writer.WriteLine("<li>");
}
writer.WriteLine(html.PageLink(rootLink).ToHtmlString());
writer.WriteLine("</li>");
}
// hämta ut alla barn från start
contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
var topLevelPages = contentLoader.GetChildren<PageData>(rootLink);
topLevelPages = FilterForVisitor.Filter(topLevelPages).OfType<PageData>().Where(x => x.VisibleInMenu);
var currentBranch = contentLoader.GetAncestors(contentLink).Select(x => x.ContentLink).ToList();
currentBranch.Add(contentLink);
//skriv ut dom
foreach (var topLevelPage in topLevelPages)
{
if (currentBranch.Any(x => x.CompareToIgnoreWorkID(topLevelPage.ContentLink)))
{
writer.WriteLine("<li class=\"active\">");
}
else
{
writer.WriteLine("<li>");
}
writer.WriteLine(html.PageLink(topLevelPage).ToHtmlString());
writer.WriteLine("</li>");
}
//Close top level
writer.WriteLine("</ul");
writer.WriteLine("</nav>");
}
示例2: RenderMainNavigation
public static void RenderMainNavigation(
this HtmlHelper html,
PageReference rootLink = null,
ContentReference contentLink = null,
bool includeRoot = true,
IContentLoader contentLoader = null)
{
contentLink = contentLink ??
html.ViewContext.RequestContext.GetContentLink();
rootLink = rootLink ??
ContentReference.StartPage;
var writer = html.ViewContext.Writer;
//Top level elements
writer.WriteLine("<nav class=\"navbar navbar-inverse\">");
writer.WriteLine("<ul class=\"nav navbar-nav\">");
if (includeRoot)
{
//Link to the root page
if (rootLink.CompareToIgnoreWorkID(contentLink))
{
writer.WriteLine("<li class=\"active\">");
}
else
{
writer.WriteLine("<li>");
}
writer.WriteLine(
html.PageLink(rootLink).ToHtmlString());
writer.WriteLine("</li>");
}
//Retrieve and filter the root pages children
contentLoader = contentLoader ??
ServiceLocator.Current.GetInstance<IContentLoader>();
var topLevelPages = contentLoader
.GetChildren<PageData>(rootLink);
topLevelPages = FilterForVisitor.Filter(topLevelPages)
.OfType<PageData>()
.Where(x => x.VisibleInMenu);
//Retrieve the "path" from the current page up to the
//root page in the content tree in order to check if
//a link should be highlighted.
var currentBranch = contentLoader.GetAncestors(contentLink)
.Select(x => x.ContentLink)
.ToList();
currentBranch.Add(contentLink);
//Link to the root pages children
foreach (var topLevelPage in topLevelPages)
{
if (currentBranch.Any(x =>
x.CompareToIgnoreWorkID(topLevelPage.ContentLink)))
{
writer.WriteLine("<li class=\"active\">");
}
else
{
writer.WriteLine("<li>");
}
writer.WriteLine(html.PageLink(topLevelPage).ToHtmlString());
writer.WriteLine("</li>");
}
//Close top level element
writer.WriteLine("</ul>");
writer.WriteLine("</nav>");
}
示例3: NavigationPath
private static IEnumerable<PageData> NavigationPath(ContentReference contentLink, IContentLoader contentLoader,
ContentReference fromLink = null)
{
fromLink = fromLink ?? ContentReference.RootPage;
var path =
contentLoader.GetAncestors(contentLink)
.Reverse()
.SkipWhile(x => ContentReference.IsNullOrEmpty(x.ParentLink) ||
!x.ParentLink.CompareToIgnoreWorkID(ContentReference.StartPage))
.OfType<PageData>()
.ToList();
var currentPage = contentLoader.Get<IContent>(contentLink) as PageData;
if (currentPage != null)
{
path.Add(currentPage);
}
return path;
}
示例4: NavigationPath
private static IEnumerable<PageData> NavigationPath(
ContentReference contentLink,
IContentLoader contentLoader,
ContentReference fromLink = null)
{
fromLink = fromLink ?? ContentReference.RootPage;
//Find all pages between the current and the
//"from" page, in top-down order.
var path = contentLoader.GetAncestors(contentLink)
.Reverse()
.SkipWhile(x =>
ContentReference.IsNullOrEmpty(x.ParentLink)
|| !x.ParentLink.CompareToIgnoreWorkID(fromLink))
.OfType<PageData>()
.ToList();
//In theory the current content may not be a page.
//We check that and, if it is, add it to the end of
//the content tree path.
var currentPage = contentLoader
.Get<IContent>(contentLink) as PageData;
if (currentPage != null)
{
path.Add(currentPage);
}
return path;
}