Jump to content

Add a custom message to the top of certain pages in Admin > Page Edit


LAPS
 Share

Recommended Posts

I've pages using the custom-page-template and I would like to display a simple message at the top of the page form when editing those pages in the Admin.

I thought about hooking ProcessPageEdit::buildForm() but I do not well how to use that hook in order to display the message just for the custom-page-template pages.

Any help?

 

 

UPDATE: Solution found

wire()->addHookAfter('ProcessPageEdit::buildForm', function(HookEvent $event) {
  $ProcessPageEdit = $event->object;
  $form = $event->arguments('form');
  
  switch ($ProcessPageEdit->getPage()->template->name) {
    case 'custom-page-template':
      $form->prependMarkup("<div style='margin-bottom: 3.6em; margin-top: 1em; background: #ffd;'>MY MESSAGE</div>");
	  break;
	default:
	  // do nothing
  }
});

Any improvement is welcome!

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...