Jump to content

Recommended Posts

Posted

Good day!

I have a module that sets a url hook. But then I have code in site/ready.php that stops page rendering process under certain conditions based on a page being viewed. So I need to modify that condition to include all url/path hooks. How do I do it?

I thought of setting a custom $config variable. Or checking for $config->requestPath(). But maybe there is something universal?

  • Ivan Gretsky changed the title to Determine if current request is url/path hook
Posted

I actually came across the need for this as well. @ryan - could we perhaps have: $page->isUrlHook

In my case I have url segments enabled on the homepage and some logic to process them, but that logic can't tell if it's a urlsegment or a path created by a URL hook.

I ended up with this for now:

$urlHookSegments = [];
$pathHooks = $wire->hooks->pathHooks ?? (new \ReflectionProperty($wire->hooks, 'pathHooks'))->getValue($wire->hooks);
foreach ((array) $pathHooks as $hook) {
    $match = $hook['match'] ?? '';
    if (preg_match('#^/([^/{(]+)#', $match, $m)) {
        $urlHookSegments[$m[1]] = true;
    }
}

if ($input->urlSegment1 && !isset($urlHookSegments[$input->urlSegment1])) {

 

  • 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
  • Recently Browsing   0 members

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