Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Alex Brown 129 posts 620 karma points
    Oct 25, 2016 @ 07:38
    Alex Brown
    0

    Preview Different Node in CMS

    Hello!

    I've got a node which contains a set of data, which users can add to/remove from. However, this node does not have a template and can therefore not be previewed using the Preview button in the CMS.

    I was wondering if there was a way to redirect to an ancestor node when the Preview button is clicked, as the set of data is rendered on an ancestor.

    Changing Umbraco's core in umbraco.controller.js is the last thing I want to do, so is there a more simpler way to resolve this?

    Thanks

  • Alex Brown 129 posts 620 karma points
    Oct 28, 2016 @ 14:31
    Alex Brown
    101

    For anyone who sees this in future:

    I solved this by adding an event handler which fires on page requests:

        public class ApplicationEventHandlerOverride : ApplicationEventHandler
    {
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            PublishedContentRequest.Prepared += PublishedContentRequest_Prepared;
            base.ApplicationStarted(umbracoApplication, applicationContext);
        }
    
        private void PublishedContentRequest_Prepared(object sender, System.EventArgs e)
        {
            var request = sender as PublishedContentRequest;
            if (request == null || request.TemplateAlias != MyEnums.EnumX.ToString())
                return;
    
            var ancestor = request.PublishedContent.AncestorOrSelf(3);
    
            request.SetRedirect(ancestor.Url);
        }
    }
    

    Source of my answer was found at: https://our.umbraco.org/forum/developers/api-questions/47762-redirect-all-nodes-with-no-template-to-ancestor-with-a-template-

Please Sign in or register to post replies

Write your reply to:

Draft