Sitecore - 遍历 Checkbox 的项目以设置根节点
Sitecore - Traversing items for Checkbox to set a root node
我正在寻找适用于以下 Sitecore 7 场景的网络表单解决方案。
我有一个结构,编辑器可以随时选中某个项目上的框以将其标记为根节点。我的想法是我可以检查关于我们作为根点,然后左侧菜单将只显示该项目及其兄弟。
同样,我可以为网站的那个区域重新定义一个新的 google 分析 ID
任何人都可以通过 webform 方法帮助我检查当前项目的选中字段,如果不存在则遍历直到找到该复选框并使用该找到的项目中的字段?
谢谢
您可以使用此代码遍历项目或其祖先,以找到具有选中字段的项目作为根项目
public Item GetRootItem(Item item)
{
//Check if you reached the top of your content tree, you better replace the ID with your home page item ID, and then return the home page
if(item.ID == Sitecore.Data.ID.Parse("{11111111-1111-1111-1111-111111111111}"))
return null;
//Replace CheckboxFieldName with your field name
if (item["CheckboxFieldName"] != null && item["CheckboxFieldName"] == "1")
{
return item;
}
else
{
return GetRootItem(item.Parent);
}
}
我正在寻找适用于以下 Sitecore 7 场景的网络表单解决方案。
我有一个结构,编辑器可以随时选中某个项目上的框以将其标记为根节点。我的想法是我可以检查关于我们作为根点,然后左侧菜单将只显示该项目及其兄弟。
同样,我可以为网站的那个区域重新定义一个新的 google 分析 ID
任何人都可以通过 webform 方法帮助我检查当前项目的选中字段,如果不存在则遍历直到找到该复选框并使用该找到的项目中的字段?
谢谢
您可以使用此代码遍历项目或其祖先,以找到具有选中字段的项目作为根项目
public Item GetRootItem(Item item)
{
//Check if you reached the top of your content tree, you better replace the ID with your home page item ID, and then return the home page
if(item.ID == Sitecore.Data.ID.Parse("{11111111-1111-1111-1111-111111111111}"))
return null;
//Replace CheckboxFieldName with your field name
if (item["CheckboxFieldName"] != null && item["CheckboxFieldName"] == "1")
{
return item;
}
else
{
return GetRootItem(item.Parent);
}
}