Sitecore sort children by __Created field -
i have sitecore 6.6 solution running mvc , razor. have following line;
@html.raw(sitecore.context.database.getitem(mylist.children.lastordefault()["myfield1"]).fields["myfield2"]) the above works fine, except order sorts in. need latest item based on __created field. lastordefault seems take last item in tree, not correspond actual latest created item.
can done in 1 line above?
how this:
mylist.getchildren() .orderby(x => x[sitecore.fieldids.created]) .reverse() .lastordefault() i guess work too:
mylist.getchildren() .orderby(x => x.statistics.created) .reverse() .lastordefault() keep in mind though first children retrieved , sorting happen. if have lot of children slow.
one general note, shouldn't in view really. you're putting logic in there. model should provide item need (last created).
Comments
Post a Comment