Domanda

I have a script that list's all of my newsitems. Right now my output is:

<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>

What I wish to do is:

  • Create a wrapping div around all of the "top-news" article items

The code looks like this:

@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>
}
È stato utile?

Soluzione

You should split your list in two:

@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>
}

And then wrap div around what you need.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top