I'm writing my own ContentFinder and I'm already able to set the node, but when I go the correct url it only shows a blank page and not the template set on the node. I expected that it would show the correct template because the node was set on contentRequest.PublishedContent.
Here is my code:
public class ContentFinder : IApplicationEventHandler
{
public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
ContentFinderResolver.Current.InsertTypeBefore<ContentFinderByNotFoundHandlers, MyContentFinder>();
}
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
}
}
public class MyContentFinder : IContentFinder
{
#region Properties
private UmbracoHelper _umbraco;
public UmbracoHelper Umbraco
{
get
{
return _umbraco ?? (_umbraco = new UmbracoHelper(UmbracoContext.Current));
}
}
#endregion
public bool TryFindContent(PublishedContentRequest contentRequest)
{
try
{
if (contentRequest != null)
{
var path = contentRequest.Uri.GetAbsolutePathDecoded();
var parts = path.Split(new[] { '/' }, System.StringSplitOptions.RemoveEmptyEntries);
if (parts.Length > 1)
{
var brokerParent = Umbraco.TypedContent(1136);
var nodeName = parts[1];
var node = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetByRoute("/" + brokerParent.Name + "/" + nodeName + "/");
if (node != null && node.DocumentTypeAlias == "GeneralDataBrokerDetails")
{
contentRequest.PublishedContent = node;
contentRequest.TrySetTemplate("TestBroker");
}
}
}
}
catch(Exception ex)
{
Umbraco.LogException(ex);
}
return contentRequest.PublishedContent != null;
}
}
It doesn't matter if I remove the contentRequest.TrySetTemplate("TestBroker"); code. Is there something else I need to do?
I found the problem myself. Turns out that in my default controller I did some if statements and it would return null if it didn't match those statements. With the ContentFinder it didn't match those statements. After changing that to return CurrentTemplate(model); instead of null it worked :).
ContentFinder and related template
Hello,
I'm writing my own ContentFinder and I'm already able to set the node, but when I go the correct url it only shows a blank page and not the template set on the node. I expected that it would show the correct template because the node was set on contentRequest.PublishedContent.
Here is my code:
It doesn't matter if I remove the contentRequest.TrySetTemplate("TestBroker"); code. Is there something else I need to do?
Jeroen
I found the problem myself. Turns out that in my default controller I did some if statements and it would return null if it didn't match those statements. With the ContentFinder it didn't match those statements. After changing that to return CurrentTemplate(model); instead of null it worked :).
is working on a reply...