本文介绍了在Sitecore上实现面包屑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只想问一下这里是否有人在Sitecore中做过面包屑.我目前正在做一个Sitecore 8 MVC项目,该项目需要有面包屑.
I just wanna ask if there is someone here that have already made a breadcrumbs in Sitecore. I'm currently doing a Sitecore 8 MVC project that needs to have a breadcrumbs.
当前,我看到此网站 http://blog.ryanbailey.co.nz/2015/05/breadcrumbs-for-pages-in-sitecore.html .但这对我来说还行不通,因为我不知道要参考什么.
Currently I saw this website http://blog.ryanbailey.co.nz/2015/05/breadcrumbs-for-pages-in-sitecore.html. But It doesn't work for me yet because I don't know what to reference.
我只需要知道如何获取当前页面路径中的每个项目,我已经可以处理它.
I just need to know how to get every item in the path of my current page I can handle it already.
谢谢
推荐答案
应该执行以下操作:
public ICollection<Item> GetBreadcrumbs(Item current, SiteContext site)
{
Item homeItem = site.StartItem;
List<Item> breadcrumbs = new List<Item>();
while (current != null)
{
// You may want to add additional logic to opt in/out of
// the breadcrumb based on a template/field
breadcrumbs.Add(current);
if (current == homeItem)
break;
current = current.Parent;
}
breadcrumbs.Reverse();
return breadcrumbs;
}
然后:
var breadcrumbs = GetBreadcrumbs(Context.Item, Context.Site);
这篇关于在Sitecore上实现面包屑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!