I've a document type (dtProject) with a property 'property1' of type Date Picker. I added some test items to the sitestructure and now I want to have a list\collection of these items, ordered by property1. I've code below (coll_1 is working, tried coll_2, coll_3, coll_4, but they give 'Error loading MacroEngine script') :
@inherits umbraco.MacroEngines.DynamicNodeContext
@{ var item = Model; }
var config = Model.NodeById(1085); var projectsNode = Model; if (config.HasValue("config_projectsNode")) { projectsNode = Model.NodeById(config.config_projectsNode); }
var coll_1 = newsNode.Children.Where("Visible").OrderBy("CreateDate");
var coll_2 = newsNode.Children.Where("Visible").OrderBy("property1"); var coll_3 = newsNode.Children.Where("Visible").OrderBy(x => x.GetPropertyValue("property1")); var coll_4 = newsNode.Children.Where("Visible").OrderBy(x => x.GetPropertyValue<DateTime>("property1")).ThenBy(x => x.CreateDate);
First thing, with Umbraco v7 it is not recommended that you use Scripting Files (dynamic node) this is only supported for legacy. If you are using MVC templates then you can have your Razor logic directly in your View or Partial Views. If you are using MasterPage templates then it's recommend that you use Partial View Macro's.
So using one of the above, there are two ways to get this collection, either with a typed or dynamic model.
Typed:
var myCollection = Model.Content.AncestorOrSelf(1).Descendants("dtProject").OrderBy(x => x.GetPropertyValue<DateTime>("property1"));
Dynamic:
var myDynCollection = CurrentPage.AncestorOrSelf(1).Descendants("dtProject").OrderBy("property1");
How to sort on property
Hi,
Can somebody help me with the next situation:
I've a document type (dtProject) with a property 'property1' of type Date Picker.
I added some test items to the sitestructure and now I want to have a list\collection of these items, ordered by property1.
I've code below (coll_1 is working, tried coll_2, coll_3, coll_4, but they give 'Error loading MacroEngine script') :
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var item = Model;
}
var config = Model.NodeById(1085);
var projectsNode = Model;
if (config.HasValue("config_projectsNode"))
{
projectsNode = Model.NodeById(config.config_projectsNode);
}
var coll_1 = newsNode.Children.Where("Visible").OrderBy("CreateDate");
var coll_2 = newsNode.Children.Where("Visible").OrderBy("property1");
var coll_3 = newsNode.Children.Where("Visible").OrderBy(x => x.GetPropertyValue("property1"));
var coll_4 = newsNode.Children.Where("Visible").OrderBy(x => x.GetPropertyValue<DateTime>("property1")).ThenBy(x => x.CreateDate);
Thanks,
Onno
Hi Onno,
First thing, with Umbraco v7 it is not recommended that you use Scripting Files (dynamic node) this is only supported for legacy. If you are using MVC templates then you can have your Razor logic directly in your View or Partial Views. If you are using MasterPage templates then it's recommend that you use Partial View Macro's.
So using one of the above, there are two ways to get this collection, either with a typed or dynamic model.
Typed:
Dynamic:
Jeavon
Hi Jeavon,
Tried both Typed and Dynamic in a Partial View.
Dynamic worked fine, but typed is having problems with nullable of property1
thanks
Great, lets get rid of those null values then:
is working on a reply...