Query filter filter projection based on another module field

In Orchard 1.6 I defined a custom content type called Offer, this offer has a package field. On a page displaying one offer, I want to display a short list of other offers with the same package.

For this I tried to do a projection, but how can I specify in the request filters that the package field should be equal to the package field of the currently proposed proposal?

Thank.

+3


source to share


2 answers


You can write a content handler to store the currently displayed content item for later use in a request:

public class MyContentHandler : ContentHandler
{
    readonly IOrchardServices orchardServices;

    public MyContentHandler (
        IOrchardServices orchardServices)
    {
        this.orchardServices = orchardServices;            
    }

    protected override void BuildDisplayShape(BuildDisplayContext context)
    {
        if (context.DisplayType == "Detail" && ((IShape)context.Shape).Metadata.Type == "Content" &&
            orchardServices.WorkContext.GetState<ContentItem>("currentContentItem") == null)
        {
            orchardServices.WorkContext.SetState("currentContentItem", context.ContentItem);
        }
    }
}

      



Then you can write a projection filter using the content item reference stored in the state. (See Orchard.Tags.Projections.TagsFilter for an example of how to write a projection filter.)

+2


source


I don't think this is possible at this time. You will have to write your own code to do this, I'm afraid.



0


source







All Articles