This is the Sitecore structure for wildcard item (*)
- sitecore
- content
- Site name
- Home
- Blogs
- *
- Blogs
- Globals
- Blogs Folder
- Year
- Month
- Blog Article 1
- Blog Article 2
- Blogs Folder
- Home
- Site name
- content
So according to this structure, we have #Wildcard Item(*) under the home node. It is like Blog detail page that is under Blog landing page.
First I have added new configuration file (z.wildcard.config) with the following configurations
- created httpRequestBegin processor as a batch to be executed after Item Resolver to Call Wildcard processor
- Sitecore 8.1 observed the following issues
- 1. Wildcard items no longer work
- 2. Presentation for cloned items not found
Solution:
If you are using MVC with Sitecore 8.1 then add <mvc.getPageItem> after our processor to avoid any route conflict
The last point is to add settings to disable ItemResolving.FindBestMatch because it's enabled in Sitecore 8.1 which may cause wildcard redirect issues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> | |
<sitecore> | |
<pipelines> | |
<httpRequestBegin> | |
<processor type="WildcardProject.Pipelines.HttpRequest.WildCardItemResolver,WildcardProject" patch:after="processor[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']" /> | |
</httpRequestBegin> | |
<mvc.getPageItem> | |
<processor type="WildcardProject.Pipelines.GetPageItem.GetWildCardPageItemProcessor,WildcardProject" patch:before="processor[@type='Sitecore.Mvc.Pipelines.Response.GetPageItem.GetFromRouteValue, Sitecore.Mvc']"></processor> | |
</mvc.getPageItem> | |
</pipelines> | |
<setting name="ItemResolving.FindBestMatch"> | |
<patch:attribute name="value">Disabled</patch:attribute> | |
</setting> | |
</sitecore> | |
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GetWildCardPageItemProcessor : GetPageItemProcessor | |
{ | |
public GetWildCardPageItemProcessor() | |
{ | |
} | |
public override void Process(GetPageItemArgs args) | |
{ | |
Assert.ArgumentNotNull(args, "args"); | |
if (args.Result != null) | |
{ | |
return; | |
} | |
if(Context.Item ==null || !Context.Item.TemplateID.ToString().Equals(Constants.BlogCatgeories.BlogTemplateId)) \\BlogsTemplete ID as constant | |
{ | |
return; | |
} | |
args.Result = ResolveItem(args); | |
} | |
protected Item ResolveItem(GetPageItemArgs args) | |
{ | |
return Context.Item; | |
} | |
} |
- Add class WildCardItemResolver which include the processor to resolve wildcard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WildCardItemResolver : HttpRequestProcessor | |
{ | |
public override void Process(HttpRequestArgs args) | |
{ | |
if (Context.Site.Name.Equals("shell", StringComparison.InvariantCultureIgnoreCase) | |
|| Context.Domain.Name.Equals("sitecore", StringComparison.InvariantCultureIgnoreCase)) | |
return; | |
Assert.ArgumentNotNull(args, "args"); | |
if (Context.Database == null | |
|| args.Url.ItemPath.Length == 0 | |
|| Context.Item == null | |
|| !Context.Item.TemplateID.ToString().Equals(Constants.TemplateID)) | |
return; | |
Item wildCardItem = Repository.FindByUrlPath(args.Url.FilePath); | |
if (wildCardItem != null) | |
{ | |
Context.Item = wildCardItem; | |
} | |
} | |
} | |
public static Item FindByUrlPath(string urlPath) | |
{ | |
try | |
{ | |
if (string.IsNullOrEmpty(urlPath)) | |
{ | |
return null; | |
} | |
Item blogItem = null; | |
string term = urlPath.Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries).Last(); | |
term = term.Replace("-", " "); | |
if (string.IsNullOrEmpty(term)) | |
return null; | |
var blogIndex = ContentSearchManager.GetIndex("sitecore_web_index"); | |
using (var context = blogIndex.CreateSearchContext()) | |
{ | |
List<SearchResultItem> results = context.GetQueryable<SearchResultItem>() | |
.Where(x => x.Paths.Contains(new ID([StartupPathItemID])) && x.TemplateId == new ID([TemplateId]) && x.Name == term).ToList(); | |
if (results.Any()) | |
{ | |
blogItem = results.First().GetItem(); | |
return blogItem; | |
} | |
return null; | |
} | |
} | |
catch (Exception e) | |
{ | |
Log.Error("An error occured on blog wildcard FindByUrlPath ", e.InnerException); | |
return null; | |
} | |
} | |
Hi, I am unable to find GetWildCardPageItemProcessor processor in this blog. Please help on same if there is any other blog post. Also i want to understand how are you cloning presentation to resolved items.
ReplyDeletePlease help and suggest.
Hi,
DeleteThank you for letting me know,I just added GetWildCardPageItemProcessor class, hope it is helpful now.
Thanks for helping out :)
DeleteCloning is acheived as soon as he returns "return Context.Item;" from the pageItem pipeline , the next processor has that info in the "args". As we know in Sitecore the data in pipeline args is transferred from processor to processor. Correct me if I my understanding is incorrect @Hanin
Delete