Notifications system - Save and preview
# help-with-umbraco
s
Hi folks, My team and i, are trying to achieve some custom handling, when the user clicks the "Save and preview" button. Our goal is to do some custom handling on the data that is saves (the code for this is already made), but we are having some problems, finding the right way to ensure that the data is saved, before the user is redirected to the preview site. We have tried to make a custom handler, for when the ContentSavedNotification is triggered, but the same event is also emitted, when the user clicks the normal "save" button. Is there any way to differentiate between the two buttons, so we can do our custom logic correcly?
s
From what I recall, the save and preview (in pseudo) pushes the save button and then launches the preview after
Is the custom logic for the output of preview or something else?
s
Hi @Sean Thorne, yes the custom logic is for the output of the preview. I have had the same idea on how the button works. Hopefully, we can do something else.
s
One way I solved this (by changing the output of the preview window) was to override the content finders. I created custom files: /// 1. PreviewContentFinder /// 2. FrontendPreviewController /// 3. FrontendPreviewContentFinder Making sure that my content finder is before Umbraco's preview one. The content finder just takes the content and redirects to our custom controller (so we do our logic there)
Copy code
// let's construct the url to our new custom preview controller 
            var customPreviewUrl = $"{baseUrl}/umbraco/surface/FrontendPreview/index?id={documentId}";

            // success! Redirect to our custom preview controller
            request.SetRedirect(customPreviewUrl);
Not sure if this is the ideal of efficient way, but it works really well. When you hit save & preview, it hits out content finder, in there we just redirect to our custom controller (which then redirects to another). There may be some hook into there that you can insert your custom logic 🙂
s
Perfekt, thanks Sean 😄 i will give it a try