3

I need to resolve the wildcard item (*) to a product repository which has products and show the presentation details of the (*) item.

Now i am using the following structure

  • Products
    • Product Collection 1
      • * (presentation details)
    • Product Collection 2
      • *  (presentation details)
    • Product Collection 3
      • *  (presentation details)

 

  • Global Repository
    • Products
      • Product 1 (no  presentation details)
      • Product 2 (no  presentation details)
      • Product 3 (no  presentation details)

I am using Adam Conn's wildcard module and have setup the routes for routing the (*) item to the repository item. Also have created a custom wild card item resolver (after the item resolver) to get the wildcard item as context item, which is resolving as expected.

But the issue is the resolved item does not have presentation details and I need to use that item as a datasource for the (*) item.

I have tried to use this from blog : http://hdaoud.blogspot.com/2017/05/sitecore-resolve-wildcard-item-and-fix.html

and also found some details about the same in https://community.sitecore.net/developers/f/8/t/3655

Please help me on to solve this issue.

Thanks

2

If you have your custom WildcardItemResolver processor, set the wildcard item in HttpContext.Current.Items before replacing it with your product item, e.g.:

class WildcardItemResolver : HttpRequestProcessor
{
    public override void Process(HttpRequestArgs args)
    {
        // your code here
        // before you set Sitecore.Context.Item to the product item, save wildcard item reference
        HttpContext.Current.Items["MyWildcardItem"] = Sitecore.Context.Item; 
        Sitecore.Context.Item = myProductItem;
    }
}

Now create GetFromWildcardItemLayoutField processor which will be executed before the default GetFromLayoutField and which will read the presentation details from the wildcard item instead of reading from the product item:

class GetFromWildcardItemLayoutField : GetFromLayoutField
{
    protected override XElement GetFromField(GetXmlBasedLayoutDefinitionArgs args)
    {
        var myWildcardItem = HttpContext.Current.Items["MyWildcardItem"] as Item;

        if (myWildcardItem != null)
            return GetFromField(myWildcardItem);

        return null;
    }
}

and register the processor before the default GetFromLayoutField:

<mvc.getXmlBasedLayoutDefinition>
  <processor type="Your.Assembly.Namespace.GetFromWildcardItemLayoutField, Your.Assembly"
     patch:before="processor[@type='Sitecore.Mvc.Pipelines.Response.GetXmlBasedLayoutDefinition.GetFromLayoutField, Sitecore.Mvc']" />
</mvc.getXmlBasedLayoutDefinition>
0

The answer is dynamic, you will need to assign the data source to the rendering. As we know that rendering depends on the RenderingContext.Current.Rendering.DataSource and instead of assigning the data source in presentation details rendering, you will need to assign it dynamically.

To achieve this you need to write one pipeline mvc.getRenderer and assign the data source runtime by overriding the process method of the pipeline based on the URL requested. So once you will hit the All products page URL with the product code or name, we will get that product item from the Global Repository/Products folder and assign it to the rendering data source, if it does not found then we will redirect it to the 404 pages.

About the implementation, you can refer to blog post: Wildcard Item in Sitecore

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.