Copied to clipboard

Flag this post as spam?

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


  • Steffen Hornbæk Nielsen 42 posts 133 karma points
    Jan 10, 2024 @ 09:34
    Steffen Hornbæk Nielsen
    0

    Add custom handler to "save and preview" event?

    Hi folks,

    I im trying to create a custom handler, for when the button "save and preview" is pressed. So far i haven't had any luck doing this, as i have been trying to achieve this using the normal notification system in Umbraco 11.

    We are doing som custom handling on save, but we need to know if the user pressed the "Save and preview" button instead of just save.

    Anyone with an idea on how to achieve this?

  • Steffen Hornbæk Nielsen 42 posts 133 karma points
    Jan 15, 2024 @ 13:39
    Steffen Hornbæk Nielsen
    0

    I have had some time to look more into this and these are my findings.

    1. The "Save and preview" works by first saving the content, and then "ui" does the go-to-preview bit.
    2. It is not directly possible by default, to interupt the event, since umbraco does not produce such an event.

    Solution: Hijack the preview url using a new controller class, and do the custom handling of data, before redirecting the user further.

    Hope this can help other people in the future, but please Umbraco, add this to the event system - please :D

  • Asembli 81 posts 255 karma points
    Jan 15, 2024 @ 21:21
    Asembli
    0

    I usually don't like to give links, but doesn't this help you? https://docs.umbraco.com/umbraco-cms/reference/notifications/contentservice-notifications ?

    I just copy-pasted this example and it works ok. All the events you need are covered here.

    You can only rename DontShout to something more edible :)

    Regards

Please Sign in or register to post replies

Write your reply to:

Draft