Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Hi Janmejay,
I'm intrigued—what scenario do you have where you would want the sort order to differ between edit mode and what visitors see? Reordering content is (usually) done expressly to change the order content appears on the site and not just for editor convenience (similarly, don't editors expect content to be structured as visitors see it?).
With that disclaimer, if you wanted to build a menu with a different sort order (for example) couldn't you just introduce a new sort index property and use LINQ to order by that?
Something like:
public virtual int MenuSortIndex { get; set; }
and then:
pages.OrderBy(x => x.MenuSortIndex);
Hi Jacob,
We have already sorting implemented in application. and its working well. but now editor wants that, website should show always latest fisrt articles even if editors changes the sort order of pages in episerver.
for that one option i am thinking is to go every places where we are getting the pages for all the blocks and apply OrderByDescending(x =>x.StartPublish) so it will return latest first.
we are using now
List<PageData> children =
DataFactory.Instance.GetChildren(pageLink, LanguageSelector.AutoDetect(true)).Where(c =>c.CheckPublishedStatus(PagePublishedStatus.Published)).ToList();
in this query if i apply OrderByDescending(x =>x.StartPublish) then its returning the latest first. but the problem is we have many blocks with different page type and i have to go every places and apply OrderByDescending(x =>x.StartPublish) to make sure that application should return latest first always.
So i wanted to know that is there any configuration or any easy way to do this?
avoid `DataFactory` type if you are on some latest Episerver versions..
don't think that there is some global switch to perform this sorting unobtrusively for you. and IMHO it might be even harmful in some places where you would not like to receive pages back in some sorted order. so I think that this explicit sorting is best bet.
`IContentRepository` that you got from IoC container via constructor injection (preferrably)
I am trying to make this query to use IContentRepository but i am getting error
Current query:-
DataFactory.Instance.GetChildren(pageLink, LanguageSelector.AutoDetect(true)).Where(c =>c.CheckPublishedStatus(PagePublishedStatus.Published)).ToList();
I tried:-
var loader = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentLoader>();
loader.GetChildren(pageLink, LanguageSelector.AutoDetect(true)).Where(c => c.CheckPublishedStatus(PagePublishedStatus.Published)).OrderByDescending(x => x.StartPublish).ToList();
I am gettin compilation error
GetChildren from the injected services are generic so should be called with the type. Try
GetChildren<PageData> instead or you can pass whatever base types you use.
Also make sure to use IContentLoader when you are just reading and IContentRepository when you need to update/save things, it's better performance.
Also as a guide you never want to call EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance in code, you want to pass your services in the constructor of your classes or lazy load them using Injected<T> (preferrable contructor injected as Injected<T> is a bit of an anti pattern)
Also as a guide you never want to call EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance in code, you want to pass your services in the constructor of your classes or lazy load them using Injected<T> (preferrable contructor injected as Injected<T> is a bit of an anti pattern)
When editor changes sorting order of the pages in Episerver editing mode, its affecting the website pages sort order also. means website pages are also changes sorting order that happens in episerver.
how we can sort order of pages in episerver in a way that it should not affects website page sorting order.
Is there any configuration or settings in episerver?