我如何可以访问所有属性在一个选项卡中的一把umbraco节点?节点、选项卡、属性、umbraco

2023-09-06 15:42:23 作者:柒夏

有没有办法,我可以访问使用C#标签的一把umbraco的方法吗?我通过每一个属性在某个特定的标签,这样我可以显示/隐藏取决于该选项卡中是否有它的内容或不是网站的该部分试图循环。

Is there a way that I can access tabs in umbraco using C#? I am trying to loop through each property in a particular tab so that I can show/hide that section of the website depending on whether that tab has content in it or not.

我已经试过 ContentType.Tab.GetTab(); 但是这有一个id,我无法找到一个标签ID的任何位置

I have tried ContentType.Tab.GetTab(); but that takes an id and I can't find a tab id anywhere.

感谢。

推荐答案

您可以使用 getVirtualTabs 方法,则该选项卡内环路的foreach属性

you can use getVirtualTabs method then loop foreach property inside that tab

Node current = Node.GetCurrent();
DocumentType dt = DocumentType.GetByAlias(current.NodeTypeAlias);
if (dt != null) {
    foreach(var tab in dt.getVirtualTabs) { //get all tabs
        foreach(var propertyType in tab.PropertyTypes) { //loop through each property inside the Tab
            // propertyType.Name
            //....write here your code
        }
    }
}