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.
public class CustomControllerRouteController : RenderController
{
public CustomControllerRouteController(ILogger<RenderController> logger, ICompositeViewEngine compositeViewEngine, IUmbracoContextAccessor umbracoContextAccessor) : base(logger, compositeViewEngine, umbracoContextAccessor)
{
}
public override IActionResult Index()
{
// you can access the CurrentPage directly in the controller, but just so you know you can use it:
var currentPage = CurrentPage;
if (UmbracoContext.InPreviewMode)
{
// Do something
}
// maybe do an else here, depending on what you want to do above
return CurrentTemplate(CurrentPage);
}
}
Then in your program.cs below the .Build() of your builder.CreateUmbracoBuilder add:
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?
I have had some time to look more into this and these are my findings.
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
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
I might be a little late to the party, but check this page out: https://docs.umbraco.com/umbraco-cms/reference/routing/custom-controllers
Then in your program.cs below the
.Build()
of yourbuilder.CreateUmbracoBuilder
add:is working on a reply...