Copied to clipboard

Flag this post as spam?

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


  • DonZalmrol 220 posts 833 karma points
    Nov 13, 2016 @ 12:39
    DonZalmrol
    0

    Get items of a page within a page?

    Hi all,

    I'm busy creating a new website for my work and I am stuck with listing all of our press releases.

    We work with pages that contain the years 2017-2009 and an archive folder that has all the pre-2009 press releases stored till 2004.

    2017-2009 is working without any issues, I have my list like you can see and it dynamically grows and shrinks.

    My archive page however is not working. It shows the years (2x) and will not list the date nor the name of press release like on the other pages.

    The 2x year listing comes due to my foreach loop, as it has two year for testing (2008 and 2007).

    What I wish to achieve with the archive page is this

    | +-- 2008 | +-- Press release 1 | +-- Press release 2 | +-- Press release x | +-- 2007 | +-- Press release 1 | +-- Press release x | | 200x | +-- Press release x | +-- 2004 +-- Press release x

    Any help is deeply appreciated :)

    Non archived press releases Archived press releases

    The code I'm using is this one:

        @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
        var selectionYears = CurrentPage.Site().FirstChild("investorsPage").FirstChild("textPage").FirstChild("presentationPage").Children("pressReleasesYearItem");
        var selectionReleases = CurrentPage.Site().FirstChild("investorsPage").FirstChild("textPage").FirstChild("presentationPage").Children("presentationItem");
    
        var currentPageName = @Umbraco.Field("pageName").ToString();
    }
    
    
    
    <ul class="nav nav-tabs" style="border-bottom: 1px solid #ddd;">
    
        @* Go to the year pages and list them *@
        @foreach (var year in selectionYears)
        {
            @* Set the active year -> active *@
            if (@year.Name == @currentPageName)
            {
                <li class="nav active"><a href="@year.Name" data-toggle="tab">@year.Name</a></li>
            }
    
            @* Show the other years as regular years (non-active)*@
            else
            {
                <li><a href="@year.Name" data-toggle="tab">@year.Name</a></li>
            }
        }
    
    </ul>
    
    <br />
    
    @*  List content of the selected year (page) *@
    <div class="table-responsive">
    
        <table class="table table-striped">
    
            <thead>
                <tr>
                    <th>Date</th>
                    <th>Name</th>
                </tr>
            </thead>
    
            <tbody>
    
                @foreach (var page in @CurrentPage.AncestorOrSelf().Children)
                {
                    @* Show archived presentations *@
                    if (@currentPageName == "Archive")
                    {
                        foreach(var page1 in @CurrentPage.AncestorOrSelf(10).Children)
                        {
                            <tr>
                                @* Test *@
                                <td>@page1.Name</td>
    
                                <td>@page1.date.ToString("dd-MM-yyyy")</td>
                                <td><a href="@page1.Url">@page1.title</a></td>
                            </tr>
                        }
                    }
    
                    @* Show visible year presentations (non-archived)*@
                    else
                    {
                        <tr>
                            <td>@page.date.ToString("dd-MM-yyyy")</td>
                            <td><a href="@page.Url">@page.title</a></td>
                        </tr>
                    }
                }
    
            </tbody>
        </table>
    </div>
    
  • DonZalmrol 220 posts 833 karma points
    Nov 13, 2016 @ 14:03
    DonZalmrol
    0

    I'm progressing. Now I need to set the correct press release item name.

    enter image description here

  • DonZalmrol 220 posts 833 karma points
    Nov 13, 2016 @ 14:52
    DonZalmrol
    0

    When I call the item directly with a query this works (like all my other code). But I can't seems to call something like this:

    Root -> EN -> Investors -> Company-News-Reports -> Press Releases -> Archive

    Then under archive list all my press releases that are archived: 2008, 2007, 2006, ...

    From those then display it's year, date and name.

    enter image description here

    My current code:

        @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
        var selectionYears = CurrentPage.Site().FirstChild("investorsPage").FirstChild("textPage").FirstChild("presentationPage").Children("pressReleasesYearItem");
        var selectionReleases = CurrentPage.Site().FirstChild("investorsPage").FirstChild("textPage").FirstChild("presentationPage").Children("presentationItem");
    
        var currentPageName = @Umbraco.Field("pageName").ToString();
    }
    
    
    @{
        var selection = Umbraco.Content(2833).Children("presentationItem");
    }
    <ul>
        @foreach(var item in selection){
            <li>
                <a href="@item.Url">@item.Name</a>
                <a href="@item.Url">@item.date.ToString("dd-MM-yyyy")</a>
                <a href="@item.Url">@item.title</a>
            </li>
        }
    </ul>
    
    
    
    
    
    
    <ul class="nav nav-tabs" style="border-bottom: 1px solid #ddd;">
    
        @* Go to the year pages and list them *@
        @foreach (var year in selectionYears)
        {
            @* Set the active year -> active *@
            if (@year.Name == @currentPageName)
            {
                <li class="nav active"><a href="@year.Name" data-toggle="tab">@year.Name</a></li>
            }
    
            @* Show the other years as regular years (non-active)*@
            else
            {
                <li><a href="@year.Name" data-toggle="tab">@year.Name</a></li>
            }
        }
    
    </ul>
    
    <br />
    
    @*  List content of the selected year (page) *@
    <div class="table-responsive">
    
        @* Show archived presentations *@
        @if (@currentPageName == "Archive")
        {
    
            foreach (var child in Model.Content.AncestorOrSelf().Children.Where(c => c.DocumentTypeAlias.Equals("pressReleasesYearItem") && c.GetPropertyValue<bool>("umbracoNaviHide")))
            {
                <table class="table table-striped">
    
                    <thead>
                        <tr>
                            <th>Year</th>
                            <th>Date</th>
                            <th>Name</th>
                        </tr>
                    </thead>
    
                    <tbody>
    
                        @if(child.Children.Any(x => x.DocumentTypeAlias.Equals("presentationItem")))
                        {
                            foreach (var page in child.AncestorOrSelf().Children.Where(p => p.DocumentTypeAlias.Equals("presentationItem")))
                            {
                                <tr>
                                    <th scope="row">@child.Name</th>
    
                                    <td>@page.Name</td>
                                    <td><a href="@page.Url">ARCHIVED PRESS RELEASE TITLE HERE</a></td>
    
                                </tr>
                            }
                        }
    
                    </tbody>
                </table>
            }
        }
    
        @* Show visible year presentations (non-archived)*@
        else
        {
            <table class="table table-striped">
    
                <thead>
                    <tr>
                        <th>Date</th>
                        <th>Name</th>
                    </tr>
                </thead>
    
                <tbody>
    
                    @foreach (var page in @CurrentPage.AncestorOrSelf().Children)
                    {
                        <tr>
                            <td>@page.date.ToString("dd-MM-yyyy")</td>
                            <td><a href="@page.Url">@page.title</a></td>
                        </tr>
                    }
    
                </tbody>
            </table>
        }
    
    </div>
    
  • DonZalmrol 220 posts 833 karma points
    Nov 13, 2016 @ 15:37
    DonZalmrol
    100

    Got it!

    I needed to fetch the ID's and extract the content from it. Code is working :)

    Now I need to fix my navigation issue on the years. That will be a different topic.

    enter image description here The code of course:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
        var selectionYears = CurrentPage.Site().FirstChild("investorsPage").FirstChild("textPage").FirstChild("presentationPage").Children("pressReleasesYearItem");
        var selectionReleases = CurrentPage.Site().FirstChild("investorsPage").FirstChild("textPage").FirstChild("presentationPage").Children("presentationItem");
    
        var currentPageName = @Umbraco.Field("pageName").ToString();
    }
    
    
    <ul class="nav nav-tabs" style="border-bottom: 1px solid #ddd;">
    
        @* Go to the year pages and list them *@
        @foreach (var year in selectionYears)
        {
            @* Set the active year -> active *@
            if (@year.Name == @currentPageName)
            {
                <li class="nav active"><a href="@year.Name" data-toggle="tab">@year.Name</a></li>
            }
    
            @* Show the other years as regular years (non-active)*@
            else
            {
                <li><a href="@year.Name" data-toggle="tab">@year.Name</a></li>
            }
        }
    
    </ul>
    
    <br />
    
    @*  List content of the selected year (page) *@
    <div class="table-responsive">
    
        @* Show archived presentations *@
        @if (@currentPageName == "Archive")
        {
    
            foreach (var child in Model.Content.AncestorOrSelf().Children.Where(c => c.DocumentTypeAlias.Equals("pressReleasesYearItem") && c.GetPropertyValue<bool>("umbracoNaviHide")))
            {
                <table class="table table-striped">
    
                    <thead>
                        <tr>
                            <th>@child.Name</th>
                            <th>Date</th>
                            <th>Name</th>
                        </tr>
                    </thead>
    
                    <tbody>
    
                        @if(child.Children.Any(x => x.DocumentTypeAlias.Equals("presentationItem")))
                        {
                            @* Initialize the counter *@
                            var count = 0;
    
                            @*foreach (var page in child.AncestorOrSelf().Children.Where(p => p.DocumentTypeAlias.Equals("presentationItem")))*@
                            foreach(var page in child.AncestorOrSelf().DescendantsOrSelf())
                            {
                                @* Fetch the content from the page.Id we've fetched *@
                                var fetchContent = Umbraco.Content(@page.Id).Children();
    
                                @* Go over the items within fetchContent to list them *@
                                foreach(var item in fetchContent)
                                {
                                    @* Create a little item counter *@
                                    count++;
    
                                    <tr>
                                        @* Set the little item counter values*@
                                        <th scope="row"># @count</th>
    
                                        @* Fill in the actual content *@
                                        <td>@item.date.ToString("dd-MM-yyyy")</td>
                                        <td><a href="@item.Url">@item.title</a></td>
                                    </tr>
                                }
                            }
                        }
    
                    </tbody>
                </table>
            }
        }
    
        @* Show visible year presentations (non-archived)*@
        else
        {
            <table class="table table-striped">
    
                <thead>
                    <tr>
                        <th>Date</th>
                        <th>Name</th>
                    </tr>
                </thead>
    
                <tbody>
    
                    @foreach (var page in @CurrentPage.AncestorOrSelf().Children)
                    {
                        <tr>
                            <td>@page.date.ToString("dd-MM-yyyy")</td>
                            <td><a href="@page.Url">@page.title</a></td>
                        </tr>
                    }
    
                </tbody>
            </table>
        }
    
    </div>
    
  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Nov 24, 2016 @ 10:48
    Alex Skrypnyk
    1

    Hi Laurens,

    Great example, thank you for sharing.

    One small issue - "selectionReleases" var isn't in use.

    I checked your code sample and "selectionReleases" var just declared and never used, try to remove it - code will be faster.

    Thanks,

    Alex

  • DonZalmrol 220 posts 833 karma points
    Dec 19, 2016 @ 15:09
    DonZalmrol
    1

    Hi Alex,

    Just back from vacation. Thanks for the information! Removed that line and indeed all is working a bit faster then before!

Please Sign in or register to post replies

Write your reply to:

Draft