Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Arulkumar Subramaniam 12 posts 62 karma points
    Jul 17, 2014 @ 18:48
    Arulkumar Subramaniam
    0

    NewsItem from Child folder

    Hi

    I have created newsitems which sits under news folder

    Also i have folders (by the datatype NewsItemsArchives) under news folder which has got the archived news items 

    Thew news items are listed by a macro(ListNewsItems)  which is powered by the MVC Partial View (listnewsitems.cshtml) . But the newsitems only in the news folder is displayed and the archived folder is not displayed . Can you please let me know how can i get the news items from the child folders as well displayed

    The code for listnewsitems.cshtml is

    @using umbraco.cms.businesslogic.media;

    @using umbraco.BusinessLogic;

    @using System.Globalization

    @using System.Text

    @using System.Text.RegularExpressions

    @using Umbraco.Core.Logging

    @using Umbraco.Web.Models

    @using Umbraco.Web;

     

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

    @{var newsItems = CurrentPage.NewsItem.Where("Visible").OrderBy("news_dateposted desc"); }

    @foreach (var item in newsItems)

    {

    <article class="news">

    <div class="row">

            <div class="small-12 columns">

    <h3><a href="@item.Url">@item.news_header</a></h3>

                <p>@item.news_dateposted.ToString("dd/MM/yy") | @item.news_postedby | <span class="green"><strong>London</strong></span></p>

    </div>

            <div class="small-12 medium-6 large-4 news-image columns">

    <figure><a href="@item.Url"><img class="shadow" src="@item.newsImageRectangle" width="244px" ></a></figure>

            </div>

    <div class="small-12 medium-6 large-8 columns post-text">

    <div class="small-12 columns"><p>@item.news_shortpost</p><a class="button" href="@item.Url">READ MORE</a></div>

                <figure>

                <a href="#" title="Post to X?"><img src="/images/news/social-icons.png" alt="Social Icons"></a>

                </figure>        

            </div>            

    </div>

        </article>

    }

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 17, 2014 @ 19:11
    Dennis Aaen
    0

    Hi Arulkumar

    If I understand you question correct you want to display the newitems that are in the archived folders too. You could use the Descendants() axe, by using the Descendants() returns either all pages (children, grandchildren and so on) below a given page in the content tree, or all pages above the current page, and the page itself.

    So try something like this:

    @using umbraco.cms.businesslogic.media;
    @using umbraco.BusinessLogic;
    @using System.Globalization
    @using System.Text
    @using System.Text.RegularExpressions
    @using Umbraco.Core.Logging
    @using Umbraco.Web.Models
    @using Umbraco.Web;

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

    @{var newsItems = CurrentPage.Descendants("NewsItem").Where("Visible").OrderBy("news_dateposted desc"); }

    @foreach (var item in newsItems){
    <article class="news">
    <div class="row">
    <div class="small-12 columns">
    <h3><a href="@item.Url">@item.news_header</a></h3>
    <p>
    @item.news_dateposted.ToString("dd/MM/yy") | @item.news_postedby | <span class="green"><strong>London</strong></span>
    </p>

    </div>

    <div class="small-12 medium-6 large-4 news-image columns">
    <figure>
    <a href="@item.Url"><img class="shadow" src="@item.newsImageRectangle" width="244px" >
    </a>
    </figure>
    </div>

    <div class="small-12 medium-6 large-8 columns post-text">
    <div class="small-12 columns"><p>@item.news_shortpost</p><a class="button" href="@item.Url">READ MORE</a></div>
    <figure>
    <a href="#" title="Post to X?"><img src="/images/news/social-icons.png" alt="Social Icons"></a>
    </figure>
    </div>

    </div>

    </article>
    }

    You can find the documentation for the available axes in razor here: http://our.umbraco.org/documentation/reference/templating/macros/razor/using-razor-axes

    Hope this helps

    /Dennis

  • Arulkumar Subramaniam 12 posts 62 karma points
    Jul 17, 2014 @ 20:27
    Arulkumar Subramaniam
    0

    Thanks Dennis

    But when i change the code to CurrentPage.Descendants("NewsItem") , it doesnt pick up any news item

    Not even the one that's in the news folder :(

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 17, 2014 @ 20:49
    Dennis Aaen
    0

    Hi Arulkumar,

    Okay, you could try use the pre-defined code snippet called List Descendants From Currentpage, as a starting ponit. and then added your markup, so it match your case.

    The snippet for List Descendants From Currentpage, looks like this.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

    @* Ensure that the Current Page has children, where the property umbracoNaviHide is not True *@
    @if (CurrentPage.Children.Where("Visible").Any())
    {
        @* Get the first page in the children, where the property umbracoNaviHide is not True *@
        var naviLevel = CurrentPage.Children.Where("Visible").First().Level;
       
        @* Add in level for a CSS hook *@
        <ul class="level-@naviLevel">           
            @* For each child page under the root node, where the property umbracoNaviHide is not True *@
            @foreach (var childPage in CurrentPage.Children.Where("Visible"))
            {
                <li>
                    <a href="@childPage.Url">@childPage.Name</a>

                    @* if the current page has any children, where the property umbracoNaviHide is not True *@
                    @if (childPage.Children.Where("Visible").Any())
                    {                   
                        @* Call our helper to display the children *@
                        @childPages(childPage.Children)
                    }
                </li>
            }
        </ul>
    }

    @helper childPages(dynamic pages)
        {
        @* Ensure that we have a collection of pages *@
        if (pages.Any())
        {
            @* Get the first page in pages and get the level *@
            var naviLevel = pages.First().Level;
           
            @* Add in level for a CSS hook *@
            <ul class="level-@(naviLevel)">
                @foreach (var page in pages.Where("Visible"))
                {
                    <li>
                        <a href="@page.Url">@page.Name</a>
                       
                        @* if the current page has any children, where the property umbracoNaviHide is not True *@
                        @if (page.Children.Where("Visible").Any())
                        {                       
                            @* Call our helper to display the children *@
                            @childPages(page.Children)
                        }
                    </li>
                }
            </ul>
        }
    }

    Hope this can help you.

    /Dennis

  • Arulkumar Subramaniam 12 posts 62 karma points
    Jul 18, 2014 @ 14:18
    Arulkumar Subramaniam
    0

    Thanks Dennis 

Please Sign in or register to post replies

Write your reply to:

Draft