If have created a comments document to become a child of a main document. I only ever show them as a list underneath the parent document (ie on the parent's template)
I am also using the excellent Frontend Editing package so users can edit from the front end.
The problem is when you save a document, it then tries to open that document.
I would prefer it to go back to the parent document. In other words, I would like it to auto redirect,
I know I could use umbracoRedirect or umbracoInternalRedirectId but that would mean manually picking the parent when editing the comment, which is undesirable. Is there any way to auto redirect to the parent node?
Otherwise, I guess I will have to do some javascript redirecting on a template on the comment
You can achieve this by creating your own UrlProvider and override the URL for nodes of type comment to redirect to its parent.
There is a great tutorial on 24days by Jeroen Breuer about creating you own UrlProvider and ContentFinder (but i dont think you need a contentfinder for this scenario): http://24days.in/umbraco/2014/urlprovider-and-contentfinder/
Based on your post and Jeroens tutorial, i think something like this would do the trick for you:
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Web;
using Umbraco.Web.Routing;
namespace MyUmbracoApplication
{
public class CommentUrlProvider : IUrlProvider
{
public string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode)
{
var content = umbracoContext.ContentCache.GetById(id);
if (content != null && content.DocumentTypeAlias == "comment" && content.Parent != null)
{
return content.Parent.Url; //The comment will be redirected to its parent.
}
return null;
}
public IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current)
{
return Enumerable.Empty<string>();
}
}
public class ApplicationStartUp : ApplicationEventHandler
{
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
UrlProviderResolver.Current.InsertTypeBefore<DefaultUrlProvider, CommentUrlProvider>();
}
}
}
I have´nt tried this together with the Frontend Editing package, but here´s the result for me when i´ve tried to set up a similar backoffice as you with articles and comments. (See animation)
Automatically redirect to parent node
If have created a comments document to become a child of a main document. I only ever show them as a list underneath the parent document (ie on the parent's template)
I am also using the excellent Frontend Editing package so users can edit from the front end.
The problem is when you save a document, it then tries to open that document.
I would prefer it to go back to the parent document. In other words, I would like it to auto redirect,
I know I could use umbracoRedirect or umbracoInternalRedirectId but that would mean manually picking the parent when editing the comment, which is undesirable. Is there any way to auto redirect to the parent node?
Otherwise, I guess I will have to do some javascript redirecting on a template on the comment
Hi Tim.
You can achieve this by creating your own UrlProvider and override the URL for nodes of type comment to redirect to its parent. There is a great tutorial on 24days by Jeroen Breuer about creating you own UrlProvider and ContentFinder (but i dont think you need a contentfinder for this scenario): http://24days.in/umbraco/2014/urlprovider-and-contentfinder/
Based on your post and Jeroens tutorial, i think something like this would do the trick for you:
I have´nt tried this together with the Frontend Editing package, but here´s the result for me when i´ve tried to set up a similar backoffice as you with articles and comments. (See animation)
Hope this could be helpful!
Thanks, that's really useful.
Pardon me if I am being stupid, but does this code go in App_Code as an addition to core Umbraco, and don't want it overwritten with new releases?
Yes, you can put it in App_Code. It wont get overwritten in future releases.
Glad i could help! Best of luck to you!!
Thanks!
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.