2014-02-28 67 views
0

我有一個腳本,列出了我所有的newsitems。 現在我的輸出是:圍繞頂部項目創建包裝div

<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> 
} 
+0

然後創建,是什麼問題? – Kuzgun

+1

爲什麼不創建2個列表,其中一個帶有topnews項目,另一個沒有,這樣您可以創建2個foreach循環? –

回答

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包圍你需要的東西。

+0

啊,從來沒有想過這個解決方案:) Thx隊友:) – nuffsaid