在顶级项目周围创建包装div

时间:2014-02-28 10:12:21

标签: c# linq razor umbraco

我有一个脚本列出了我的所有newsitems。 现在我的输出是:

<section class="news-list">            

            <article class="news-item top-news">
                <a href="/nyheder/dbu-nyhed-4/">DBU Nyhed 4 (Topnyhed)</a>
            </article>
            <article class="news-item top-news">
                <a href="/nyheder/dbu-nyhed/">DBU Nyhed (Topnyhed)</a>
            </article>
            <article class="news-item">
                <a href="/nyheder/dbu-nyhed-3/">DBU Nyhed 3</a>
            </article>
            <article class="news-item">
                <a href="/nyheder/dbu-nyhed-2/">DBU Nyhed 2</a>
            </article>

</section>

我想做的是:

  • 围绕所有“热门新闻”文章项目创建包装div

代码如下所示:

@if (CurrentPage.Children.Where("Visible").Any())
{
<section class="news-list">            
    @* For each child page under the root node, where the property umbracoNaviHide is not True *@
    @foreach (var childPage in CurrentPage.Children.Where("Visible").OrderBy("topNews desc, CreateDate desc"))
    {
        var isTopNews = childPage.topNews;
        if (isTopNews)
        {
            <article class="news-item top-news">
                <a href="@childPage.Url">@childPage.Name (Topnyhed)</a>
            </article>
        }
        else
        {
            <article class="news-item">
                <a href="@childPage.Url">@childPage.Name</a>
            </article>
        }
    }

</section>
}

1 个答案:

答案 0 :(得分:1)

您应该将列表分成两部分:

@if (CurrentPage.Children.Where("Visible").Any())
{
<section class="news-list">            
    @* For each child page under the root node, where the property umbracoNaviHide is not True *@
    @foreach (var childPage in CurrentPage.Children.Where("Visible").Where("topNews").OrderBy("CreateDate desc"))
    {
        <article class="news-item top-news">
            <a href="@childPage.Url">@childPage.Name (Topnyhed)</a>
        </article>
    }

    @foreach (var childPage in CurrentPage.Children.Where("Visible").Where("not topNews").OrderBy("CreateDate desc"))
    {
        <article class="news-item">
            <a href="@childPage.Url">@childPage.Name (Topnyhed)</a>
        </article>
    }
</section>
}

然后将div包裹在你需要的地方。