我只想问一下这里是否有人已经在Sitecore中制作了面包屑。我目前正在做一个需要有面包屑的Sitecore 8 MVC项目。
目前我看到了这个网站http://blog.ryanbailey.co.nz/2015/05/breadcrumbs-for-pages-in-sitecore.html。但它对我不起作用,因为我不知道该引用什么。
我只需要知道如何获取当前页面路径中的每个项目,我已经可以处理它了。
由于
答案 0 :(得分:3)
这样的事情应该这样做:
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);
答案 1 :(得分:2)
您可以获取当前项目,然后获取它的所有祖先。
var ancestors = currentItem.Axes.GetAncestors().ToList();
然后你可以获得家庭项目并过滤祖先以删除sitecore和内容节点。
ancestors = ancestors.SkipWhile(i => i.ID != home.Id.ToID()).ToList();
答案 2 :(得分:0)
public void GetBreadcrumbs(Item ParentItem)
{
List<BredCrumbDetails> lstBreadCrumbs = new List<BredCrumbDetails>();
string strcurrenttitle = ParentItem.Name;
Item currentitem = ParentItem;
int i = 0;
while (currentitem != null)
{
var ItemTemplateid = currentitem.TemplateID.ToString();
var FolderTemplateId = "{}";
if (ItemTemplateid != FolderTemplateId) //here we are removing folders
{
BredCrumbDetails bcDetails = new BredCrumbDetails();
if (i == 0)
{
bcDetails.BCPageLink = null;
bcDetails.Title = currentitem.Name;
bcDetails.IsVisible = true;
lstBreadCrumbs.Add(bcDetails);
}
else
{
bcDetails.BCPageLink = currentitem.Paths.FullPath;
bcDetails.Title = currentitem.Name;
bcDetails.IsVisible = true;
lstBreadCrumbs.Add(bcDetails);
}
i++;
if (currentitem.Name == ("Home"))
{
break;
}
currentitem = currentitem.Parent;
}
else
{
i++;
currentitem = currentitem.Parent;
}
}
lstBreadCrumbs.Reverse();
rptCrumbs.DataSource = lstBreadCrumbs;
rptCrumbs.DataBind();
}