Jump to content

Recommended Posts

Posted

Hi,

is there a hook after the current (active) page got created? Or which method got called in the Page class after the Constructor of the current page got initialized?

Thanks.

 

Posted
3 hours ago, monollonom said:

Have you tried with Pages::added ?

Sorry, I'm mean after a page load when the current page get fetched from the database. Page::added get called when I create a new page.

I've a use case where I want a run a method of my custom page class. But if I run the method in the constructor, not all properties of page are loaded (e.g. httpUrl). 

Posted

I've never worked with custom page classes but I assume you could add a hook on the "loaded" event of your custom page and execute your custom function, something like :

$wire->addHookAfter("CustomPage::loaded", function($event) {
	$page = $event->object;
	$page->yourCustomPageFunction();
});

 

Posted
20 hours ago, rjgamer said:

namespace ProcessWire; class DefaultPage extends Page { public function loaded(): { parent::loaded(); if ($this->isCurrent) { // to my special custom super feature stuff } } }

Are you sure you need to check? If you place a custom "loaded" method in your custom page class only pages using your custom page class will execute that code anyway... Or am I missing anything?

But if I'm missing anything checking for the current pageclass is as easy as this:

if($page instanceof self) { ... }

 

  • Like 1

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
×
×
  • Create New...