Jump to content

Conditional Hooks


Jonathan Lahijani
 Share

Recommended Posts

In 2015, Ryan introduced conditional hooks:
https://processwire.com/blog/posts/new-ajax-driven-inputs-conditional-hooks-template-family-settings-and-more/

I have the following hook which works properly:

$wire->addHookAfter('Pages::added', function($event) {
  $page = $event->arguments[0];
  if($page->template=='mytemplate') {
    // ...
  }
});

Now if I want to take advantage of conditional hooks, I should be able to do this:

$wire->addHookAfter('Pages(template=mytemplate)::added', function($event) {
  // ...
});

however the hook doesn't get hooked.  Any ideas?

Link to comment
Share on other sites

So the conditional hooks (probably) work on the $event->object of the HookEvent passed to the hook. That's why ryan's examples only use Page(…)::…. Page does not have a function added (neither hookable nor unhookable), while Pages cannot be evaluated against a selector. 

Link to comment
Share on other sites

  • 4 years later...

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...