Try our conversational search powered by Generative AI!

Episerver projects and GetChildren

Vote:
 

I want to use the Episerver projects functionality to preview my page before it's published, but it seems that i.e GetChildren does not fetch the pages "ready to publish" in the project even if I'm standing in "project mode". Is this correct functionality?

#196686
Sep 07, 2018 16:07
Vote:
 

When previewing with a project active should all loaded content items (regardless if they are loaded through Load, GetChildren or GetItems) be replaced with the version that is part of the project.

#196689
Sep 07, 2018 16:25
Vote:
 

Johan, is this the case even when a page is "published" for the first time through the project?

And, will this work with Find (if we use find to fetch pages)?

#196717
Edited, Sep 10, 2018 9:32
Vote:
 

It works so that there is a step before loading content that will check if a project is active (it is determined by checking for a query parameter 'projectid' or similar). 

Say for example that a content with id 123 on lang 'en' is requested to be loaded, then if a project with id '7' is active (with query param as above) a request is made to a project resolver component to see if there is any content version for content with id '123' on language 'en' in project with id '7'. If the project resolver returns a different version then that version is loaded instead otherwise the original one.'

I do not have full detail over how Find does it but I think the Find index only returns the content id and then the content is loaded on the CMS site so it should work there as well. Note however that the determination if a project is active is to look at a query parameter on the http request, that means that code that runs in backgrond threads without http context will not load content according to the project. 

#196757
Edited, Sep 11, 2018 7:54
Vote:
 

So i guess part of my problem is that I'm fetching pages via an ajaz call. So the epiprojects-parameter does not exist in that context.

But when I try this: 

ProjectLoaderOption option = new ProjectLoaderOption();
option.ProjectIds = new List<int>() {1};
LoaderOptions options = new LoaderOptions();
options.Add(option);

List<EventPage> pageList = _contentLoader.GetChildren<EventPage>(new ContentReference(values.SelectedPage), options)
//.FilterForDisplay()
.OrderBy(x => x.EventStart)
//.Take(values.NumberOfArticles > 0 ? values.NumberOfArticles : 100)
.ToList();

IEnumerable<IContent> filtered = FilterForVisitor.Filter(pageList);

I can see that the pageList is loaded with my testpage, but the FilterForVisitor still filters out the same testpage, hence I do not see it in the project view mode.

Is it possible to set the epiprojects-parameter programmatically?

#196766
Sep 11, 2018 10:46
Vote:
 

Either if you can apply queryparameter 'epiprojects' with the id of the project to your ajax request.

On the server side could one option to be to intercept IProjectResolver interface and have some logic there where you handle your ajax request your self and delegate other requests to the default implementation. 

#196769
Sep 11, 2018 12:31
Vote:
 

Johan, are you saying that adding epiprojects=1 to the get ajax request should be enough so that both GetChildren and FilterForVisitor automagically gets items from the project, or do I have to somehow use the value from the request? 

To be clear, getting the epiprojects-value is not the problem, the problem is to get i.e FilterForVisitor to not filter away the project-pages. (And ideally to not have to add loaderoptions to getchildren etc)

#196776
Sep 11, 2018 14:32
Vote:
 

It should be enough to add query parameter epiprojects=1 to the ajax request (given that 1 is the id for your project). Then the loading should automatically pick the project version and the filter should allow it as well.

#196778
Sep 11, 2018 14:38
Vote:
 

So, I just can't get this to work.

I have verified that value is equal to 1 (which is my project id) using the code below:

var value = HttpContext.Current.Request.QueryString["epiprojects"];

But, I see that when i try the following code:

var list = _projectResolver.GetCurrentProjects();



It returns an empty list. I think the reason is that the _contextModeResolver is null, which from reflecting the ProjectResolver.cs seems to give an empty list:

public virtual IEnumerable<int> GetCurrentProjects()
{
if (!this.IsInEditMode())
return Enumerable.Empty<int>();
IEnumerable<int> result;
if (!this._queryParameterResolver.TryGet("epiprojects", out result))
return Enumerable.Empty<int>();
return result;
}

private bool IsInEditMode()
{
if (this._contextModeResolver != null)
return ContextModeExtension.EditOrPreview(this._contextModeResolver.CurrentMode());
if (this._requestContext != null)
{
System.Web.Routing.RequestContext reqContext = this._requestContext();
if (reqContext != null)
return ContextModeExtension.EditOrPreview(RequestContextExtension.GetContextMode(reqContext));
}
return false;
}

Do you have any tips on what I can be doing wrong?

I'm using Episerver 10.9.0.0 btw

#196787
Sep 11, 2018 16:39
Vote:
 

You are right, I did not look into the code in detail, it requires that the request is in edit or preview. One option could be to add on qyery parameter epieditmode=true to the ajax reqest. This requires though that the request is under the shell module cms (path starts with /episerver/cms/....). Another option is that you before calling load sets context mode to edit or preview through extension method 

 public static void SetContextMode(this RequestContext reqContext, ContextMode value)

which requires 

using EPiServer.Web.Routing;

#196791
Sep 11, 2018 17:04
Vote:
 

I'm using apiControllers for my ajax endpoints where only HttpRequestContext is available. Am I out of luck here? I seems that I can't set the contextmode to edit.

#196816
Sep 12, 2018 12:47
Vote:
 

The owin pipeline is still executing on a http request so it should be accessible through System.Web.HttpContext.Current.Request.RequestContext 

#196818
Sep 12, 2018 13:05
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.