Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi
Struggling with some code, wonder if anyone knows how to write this.
I've got a collection of articles that have an end date specified on them. and I'm trying to only show items from a certain year.
@{ var selection = Umbraco.Content(3237).Children.Where("newsEndDate == 2016"); } @foreach (var item in selection) { <div>@item.Name</div> }
The above code doesn't work, I've also tried
@{ var selection = Umbraco.Content(3237).Children.Where("newsEndDate.ToString("yyyy") == 2017); }
But still no luck, any help would be greatly appreciated.
Thanks.
Hi David
Don't recommend you to use Dynamics in rendering of Umbraco data, try to use TypedContent instead of Content, this should work as you want:
var selection = Umbraco.TypedContent(3237).Children.Where(node => node.HasValue("newsEndDate") && node.GetPropertyValue<DateTime>("newsEndDate").Year == 2017);
Hope it will help.
Thanks,
Alex
Thanks Alex, that's worked perfect.
Could I ask you one other quick question.
So I've now got this
@{ var selection = Umbraco.TypedContent(3237).Children.Where(node => node.HasValue("newsEndDate") && node.GetPropertyValue<DateTime>("newsEndDate").Year == 2016); } @foreach (var item in selection) { <div class="date"> @item.newsEndDate.ToString("MMMM") </div> }
Since changing to Typed Content this no longer works @item.newsEndDate.ToString("MMMM") Is there another way I should be doing this now.
You are welcome, David.
Try this code:
@foreach (var item in selection) { var dateTimeValue = item.GetPropertyValue<DateTime>("newsEndDate"); <div class="date">@dateTimeValue.ToString("MMMM")</div> }
Spot on, thanks Alex
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Only show items from specified year
Hi
Struggling with some code, wonder if anyone knows how to write this.
I've got a collection of articles that have an end date specified on them. and I'm trying to only show items from a certain year.
The above code doesn't work, I've also tried
But still no luck, any help would be greatly appreciated.
Thanks.
Hi David
Don't recommend you to use Dynamics in rendering of Umbraco data, try to use TypedContent instead of Content, this should work as you want:
Hope it will help.
Thanks,
Alex
Thanks Alex, that's worked perfect.
Could I ask you one other quick question.
So I've now got this
Since changing to Typed Content this no longer works @item.newsEndDate.ToString("MMMM") Is there another way I should be doing this now.
You are welcome, David.
Try this code:
Spot on, thanks Alex
is working on a reply...