Jump to content

Tutorial: Change the page title (headline) on an edit page (ProcessPageEdit)


dotnetic
 Share

Recommended Posts

Let's assume you want to change the title of a an edit page.

You could hook ProcessPageEdit:execute in a file like site/ready.php like described here.

Adapt the template name in the following code to your needs:

$wire->addHookAfter('ProcessPageEdit::execute', function (HookEvent $event) {
  $pageEdit = $event->object;
  $page = $pageEdit->getPage();
  if ($page->template != 'shop') {
    return; // return early
  }
  $this->wire('processHeadline', 'My new headline');
// or modify the existing headline
//  $headline = $this->wire('processHeadline');
//  $this->wire('processHeadline', $headline . " - " . date('d.m.Y', $page->created));
});

 

  • Like 2
Link to comment
Share on other sites

  • dotnetic changed the title to Tutorial: Change the page title (headline) on an edit page (ProcessPageEdit)
  • 1 month later...

I don't think so. When I asked Ryan recently about modifications for our admin style he said he usually does those small modifications with JS. Not very pretty, but on the other hand this might be more robust than str_replace (which is not pretty either).

  • Thanks 1
Link to comment
Share on other sites

Thanks @bernhard

That was my thought too. It is not so important. I have now added a subheadline instead of appending something to the main headline:

$return = $event->return;
$subheadline = '<h2>My Subheadline</h2>;
$event->return = $subheadline.$return;

No I can add every markup inside the subheadline (including icons too)

Maybe a little bit offtopic:

I guess that same problem persists on modal windows. I have created an Exception to prevent unwanted publishing of pages inside the page tree and the user will get a message with additional infos.

112664868_Screenshot2024-05-11at10-19-34PagesProcessWireschulfreund_at.thumb.png.26b67ccdd6f26a8f2232f7ca98d688d9.png

I have also tried to add a little bit HTML to make the look and readability better, but without success.

The modal window will be triggered with an exception code:

throw new WireException('My exception text);

If I try to add markup to the exception text, it does not work. Do you know, if it is the same issue as with the headline?

Link to comment
Share on other sites

1 minute ago, Juergen said:
$return = $event->return;
$subheadline = '<h2>My Subheadline</h2>;
$event->return = $subheadline.$return;

Would be nice to share the whole hook 😉 

Link to comment
Share on other sites

5 minutes ago, bernhard said:

Would be nice to share the whole hook 😉 

Sure 😄

$this->addHookAfter('ProcessPageEdit::execute', $this, 'addSubTitle');

protected function addSubTitle(HookEvent $event)
        {

            // Get page being edited
            $page = $event->object->getPage();

            // Only use on pages with publishing fields
            if (!$page->hasField('jk_publish_from')) return; // this is only my restriction -> adapt it to your needs

            $subHeadline = '<p class="notes" style="padding: 5px; font-size: 20px;"><i class="fa fa-exclamation-triangle"></i>&nbsp My 		  	Subheadline</p>';

            $return = $event->return;
            $event->return = $subHeadline.$return;

        }

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...