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
I've a custom property on my doctypes ("publishdate") which is a DatePicker.
In my foreach loop I would like to check if this property has a value, and if so - check the value comparet to the current Date...
This is what I got so far, with no luck yet :|:
var startNode = Umbraco.TypedContent(Model.MacroParameters["startNodeID"].ToString());foreach(startNode.DescendantsOrSelf(4).Where(x => x.GetProperty("publishdate") != null ? x.GetPropertyValue("publishdate") >= DateTime.Now() : ""))
Hi Robin,
Instead of using the GetProperty method and GetPropertyValue method, you could try using the GetPropertyValue<> method instead where by you pass the type of the property value. So for example:
var startNode = Umbraco.TypedContent(Model.MacroParameters["startNodeID"].ToString()); foreach (startNode.DescendantsOrSelf(4).Where(x => x.GetPropertyValue<DateTime>("publishdate") >= DateTime.Now())) { // .... }
I've tried that allready - however, not all "publishdate" has a value so I need to do a check in my expression, as showed in my first example :|
Just noticed a couple of things in your original code example. The foreach loop is incorrect. The below should work.
@{ var startNode = Umbraco.TypedContent(123); foreach (var node in startNode.DescendantOrSelfs(4).Where(x => x.HasProperty("publishdate") && x.GetPropertyValue<DateTime>("publishdate") >= DateTime.Now)) { // ... } }
Thanks, Dan.
Just a thought, you might want to use the UpdateDate property as all IPublishedContent instances will have a value for this.
@{ var startNode = Umbraco.TypedContent(123); foreach (var node in startNode.DescendantOrSelfs(4).Where(x => x.UpdateDate >= DateTime.Now)) { // ... } }
Yes! - it was this snippet I was looking for:
x.HasProperty("publishdate")
It now works as intenteed... - however, I don't need the additional .Children in my foreach loop :)
Sorry Robin. I've edited my posts accordingly. Its amazing how difficult it is to differentiate between DescendantOrSelfs() and DescendantOrSelf().
:)
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Lambda sort on custom property
I've a custom property on my doctypes ("publishdate") which is a DatePicker.
In my foreach loop I would like to check if this property has a value, and if so - check the value comparet to the current Date...
This is what I got so far, with no luck yet :|:
Hi Robin,
Instead of using the GetProperty method and GetPropertyValue method, you could try using the GetPropertyValue<> method instead where by you pass the type of the property value. So for example:
I've tried that allready - however, not all "publishdate" has a value so I need to do a check in my expression, as showed in my first example :|
Just noticed a couple of things in your original code example. The foreach loop is incorrect. The below should work.
Thanks, Dan.
Just a thought, you might want to use the UpdateDate property as all IPublishedContent instances will have a value for this.
Thanks, Dan.
Yes! - it was this snippet I was looking for:
It now works as intenteed... - however, I don't need the additional .Children in my foreach loop :)
Sorry Robin. I've edited my posts accordingly. Its amazing how difficult it is to differentiate between DescendantOrSelfs() and DescendantOrSelf().
:)
is working on a reply...