cjx2240 Posted February 25, 2021 Share Posted February 25, 2021 I'd like to make a tiny tweak to the ajax page search in the top right corner of the CMS. All I want to do, is add the page's rootParent to the result dropdown. This is because due to the unique structure of a certain site, lots of pages have the same name, it's not clear which one to click on. Can anyone help me out with this please? Link to comment Share on other sites More sharing options...
monollonom Posted February 25, 2021 Share Posted February 25, 2021 Would showing the path instead of the title be okay ? I thought of a hook first but you could do the trick with a bit of CSS ul.pw-dropdown-menu-shorter li.ui-menu-item a::before { content: attr(title); margin-right: 3px; } ul.pw-dropdown-menu-shorter li.ui-menu-item a span { display: none; } (hopefully it doesn't target anything else, but from my quick testing it looks ok !) Before: After: 4 Link to comment Share on other sites More sharing options...
Robin S Posted February 25, 2021 Share Posted February 25, 2021 (edited) 6 hours ago, cjx2240 said: This is because due to the unique structure of a certain site, lots of pages have the same name, it's not clear which one to click on. The page path is in the title attribute, so you can hover on results to see the path in the browser tooltip: PW doesn't make it easy to manipulate the markup of admin search results. You could try the hook below in /site/ready.php to append the root parent title to the result title: $wire->addHookBefore('ProcessPageSearchLive::execute', function(HookEvent $event) { $event->wire()->addHookAfter('FieldtypePageTitle::wakeupValue', function(HookEvent $event) { $page = $event->arguments(0); // Limit by template or some other property of $page if($page->template == 'basic_page' && !$page->get_original_title) { $root_parent = $page->rootParent; // Set custom page property to avoid affecting root parent title $root_parent->get_original_title = true; // Append root parent title $event->return .= " (Root parent: {$root_parent->title})"; } }); }); Edited February 25, 2021 by Robin S code tweak 2 Link to comment Share on other sites More sharing options...
cjx2240 Posted March 1, 2021 Author Share Posted March 1, 2021 Both of these options are excellent, thank you ? Link to comment Share on other sites More sharing options...
szabesz Posted July 25, 2022 Share Posted July 25, 2022 Some notes on this topic: Spoiler On 2/25/2021 at 9:59 PM, Robin S said: $wire->addHookBefore('ProcessPageSearchLive::execute', function(HookEvent $event) { $event->wire()->addHookAfter('FieldtypePageTitle::wakeupValue', function(HookEvent $event) { $page = $event->arguments(0); // Limit by template or some other property of $page if($page->template == 'basic_page' && !$page->get_original_title) { $root_parent = $page->rootParent; // Set custom page property to avoid affecting root parent title $root_parent->get_original_title = true; // Append root parent title $event->return .= " (Root parent: {$root_parent->title})"; } }); }); The example above in the spoiler does not seem to work as expected (ProcessWire 3.0.184). What works for me is this: https://github.com/processwire/processwire-issues/issues/675#issuecomment-420958397 Also worth reading this discussion: https://processwire.com/talk/topic/19781-issue-with-hooking-processpagesearchexecutefor-and-the-new-search-feature-in-pw-30108/ 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now