如何根据父节点的文档类型在 foreach 循环中以不同方式显示信息?

How do I display information in a foreach loop differently depending on the parent node's doc type?

所以我有一个 foreach 循环,它当前显示一个节点列表,然后是一个嵌套的节点列表。我想稍微扩展一下,以便嵌套列表根据其父节点的文档类型看起来有所不同。

这是我正在使用的层次结构:

所以我想要一个 if 语句,我想,基本上是问 "if the parent is Player Folder, display Name and Picture of each node beneath it, if it's Character Folder, display Name and Picture and Summary, if it's anything else, just display the name")。问题是我不知道如何让它检查它是什么文档类型。

这是我目前的代码:

<section id="directoryListing">
<ul>
    @{
        var LogsNode = Model.Content.AncestorOrSelf("DirectoryLanding");
    }
    @foreach (var node in LogsNode.Children.Where("Visible"))
    {
        <li>
            <h2>@node.AsDynamic().Name</h2>
            <ul>
                @foreach (var childnode in node.Children)
                {
                    <!-- If statement would presumably begin here -->
                    <li><!-- each section of the If statement would contain something like this-->
                        <a href="@childnode.Url">@childnode.Name</a>
                    </li>
                    <!-- If statement would presumably end here -->
                }
            </ul>
        </li>
    }
</ul>
</section>

动态版本应该有 DocumentTypeAlias 属性 或 NodeTypeAlias。

您可以在此处查看很棒的作弊 sheet(也适用于 v7):

https://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets

像这样:

<section id="directoryListing">
<ul>
    @{
        var LogsNode = Model.Content.AncestorOrSelf("DirectoryLanding");

        foreach (var node in LogsNode.Children.Where("Visible"))
        {
            <li>
                <h2>@node.Name</h2>
                <ul>
                    @foreach (var childnode in node.Children)
                    {
                        if (childnode.Parent.DocumentTypeAlias == "Character")
                        {
                            <li>
                                <a href="@childnode.Url">@childnode.Name</a>
                            </li>
                        }
                        else if (childnode.Parent.DocumentTypeAlias == "Player")
                        {
                            <li>
                                <a href="@childnode.Url">@childnode.Name</a>
                            </li>
                        }
                    }
                </ul>
            </li>
        }
    }
</ul>
</section>