1

Sitecore version: 9.0 Using SXA

I have inherted a project that uses a wildcard item will try to render a route that will get pass through.

So for my example I am rendering blog articles.

So /blog/{blog-article} will render an article that my wildcard will picked up. This is all working correctly

Under blog item there are also some page item which are used to show blog posts by category, So /blog/culture doesn’t get picked up by the wildcard and will instead render the page.

However when a new page item is added, it doesn’t seem to recognise the page and instead default to the wildcard. Is there some route exception or something that needs to be populated so the wildcard will ignore certain routes? I can’t see anything obvious in Sitecore or our codebase and I've crawled through the documentation with no luck.

Wondering if there is any additional setup I could be missing.

The wildcard is currently at the top of the directory on both master and web databases

2
  • What is the order or items in Sitecore tree? Is "culture" above "*" item? And your new page, is it also above it? Oct 5, 2021 at 10:54
  • Move the wildcard to the highest sort order. (after all the items you DO want to catch)
    – Mark Cassidy
    Oct 5, 2021 at 11:04

2 Answers 2

1

My issue was to do with ItemResolvers in the end

I followed the solution mentioned on https://sitecore.stackexchange.com/a/7698/7403

Sitecore MVC resolves it (again) Which is both confusing and (I find) a little odd. But here's what's happening.

You patch after the regular ItemResolver and do your custom work. And you assume all is well from that point on. And normally it would be.

But Sitecore MVC adds a series of steps to the pipeline (for MVC requests, obviously), one of them being an execution of the mvc.getPageItem pipeline to build up the MVC-specific context class Sitecore.Mvc.Presentation.PageContext.

And mvc.getPageItem (you probably guessed it), sets a new value in Sitecore.Context.Page.

To work around this behaviour, one of the easiest approaches is to indicate (on HttpContext.Items for instance) that your processor has done work, and then check for this value at the end of the mvc.GetPageItem processor.

For previous and current Sitecore versions, @JammyKam has a full write up on his blog:

Resolving Custom Context.Item in Sitecore MVC

0

To achieve the above functionality you can perform the below steps:

  1. In a normal scenario, we create a page for each product listed under the Global/Products folder in your case it's /blog/{blog-article} and presentation details having the rendering with the respective product data source. But here we will not assign any data source into the rendering to display the product information, now the question is how information of the product will be displayed or how will you assign the data source? The answer is dynamic, we will assign the data source to the rendering. As we are aware that the rendering depends on the RenderingContext.Current.Rendering.DataSource and instead of assigning the data source in presentation details rendering we will assign it dynamically.
  2. 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 the user will hit the All products page URL with the product code or name, we will get that product item from the Global/Products folder and assign it to the rendering data source, if it does not found then we will redirect it to the 404 pages.
  3. In the configuration file, we will define the rendering name as well, so in the process method, we can identify the name of the rendering. My rendering name is ProductDetail. Here my configuration path file:
  <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <mvc.getRenderer>
        <processor type="Helixbase.Feature.Products.Pipelines.WildcardDatasource, Helixbase.Feature.Products"                  patch:before="processor[@type='Sitecore.Mvc.Pipelines.Response.GetRenderer.GetViewRenderer, Sitecore.Mvc']">
          <renderingname>ProductsDetail</renderingname>
        </processor>
      </mvc.getRenderer>
    </pipelines>
  </sitecore>
</configuration>
  1. In the process method, first, we will get the rendering name and check that The rendered page name is * and the applied rendering name is the same as we defined into the configuration file then only we will be procced. After that, we will get the product code or name from the Request URL segment and find the item with the same name or code into the product list i.e. Global/Product folder. Finally, we will assign that item to the rendering data source. Code for the configuration patch file:
namespace Helixbase.Feature.Products.Pipelines
{
    public class WildCardDataSource : GetRendererProcessor
    {
        private string RenderingName { get; set; }
        public override void Process(GetRendererArgs args)
        {
            var productsDetailRendering = RenderingName;
            if (args.PageContext.Item.Name != "*" 
                || !args.Rendering.RenderingItem.Name.Equals(productsDetailRendering, StringComparison.InvariantCultureIgnoreCase))
                return;

            if (args.PageContext.RequestContext.HttpContext.Request.Url == null) return;

            const string datasourceFolder = "/sitecore/content/Helixbase/Global/Products";
            var dataSourcePath =
                $"{datasourceFolder}/{args.PageContext.RequestContext.HttpContext.Request.Url.Segments.Last()}";

            var dataSourceItem = Sitecore.Context.Database.GetItem(dataSourcePath);
            if (dataSourceItem != null)
            {
                args.Rendering.DataSource = dataSourcePath;
            }
            else
            {
                // 404 page not found
            }
        }
    }
}  

Now in your case, you can handle the culture item into the process method and perform the operation as per your requirement.

See the blog post: Wildcard Item in Sitecore

1
  • Hi - the wild card is setup, that is not my issue. Its the fact that new pages items that sit in the directory the wildcard sits under are not rendering. However existing page items are
    – James
    Oct 6, 2021 at 8:43

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