@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>
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.
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>
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 :)
The code I'm using is this one:
I'm progressing. Now I need to set the correct press release item name.
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.
My current code:
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.
The code of course:
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
Hi Alex,
Just back from vacation. Thanks for the information! Removed that line and indeed all is working a bit faster then before!
is working on a reply...