cst989 Posted November 20, 2019 Share Posted November 20, 2019 I'd like a bookmark in the admin to a page list of pages that have a "meta title" field, so that you can quickly see which pages need updating. Without just limiting all the templates that have the field, I want something a bit more future-proof. Is this possible? If so how? I don't want to check if its empty or not equal to anything, as it would also serve to review what is there. I have ListerPro as well but can't see how to do it with either. Link to comment Share on other sites More sharing options...
dragan Posted November 20, 2019 Share Posted November 20, 2019 Well, there's no selector "if template / page has field_x", so a workaround could be two custom selectors: custom (field=value) 1 = meta%= custom (field=value) 2 = meta!= Make sure to check the checkbox on the right (make it OR rather than AND) 1 Link to comment Share on other sites More sharing options...
cst989 Posted November 20, 2019 Author Share Posted November 20, 2019 Hi @dragan thanks for the response, I think I'm misunderstanding or doing it wrong, empty fields are now being excluded. To clarify my field is meta_title - this is what I've done As you can see it matches 14 pages but there should be 16, also the number doesn't change whether using OR or AND Link to comment Share on other sites More sharing options...
dragan Posted November 20, 2019 Share Posted November 20, 2019 Try it with include=all as another filter. 1 Link to comment Share on other sites More sharing options...
dragan Posted November 20, 2019 Share Posted November 20, 2019 grumble... sorry, but my first example doesn't indeed work. It seems that this (quite surprisingly) does seem to work: page.fieldname= At least in my test-environment, it lists all pages (my field only exists in only one template) Link to comment Share on other sites More sharing options...
cst989 Posted November 20, 2019 Author Share Posted November 20, 2019 No need to apologise I really appreciate the assistance! Is this still in custom (field=value)? My field exists in about 7/10 templates, when I do meta_title= I get all pages with or without the field. Link to comment Share on other sites More sharing options...
dragan Posted November 20, 2019 Share Posted November 20, 2019 Yeah, well in that case it really seems impossible. Can't you narrow it down with some other condition? has_parent, template, or similar? I know you said you want something future-proof, but certainly you are not adding new templates every day? Field dependencies let you write your own logic in plain PHP (one of many options), I guess Ryan has a reason he didn't allow such freedom when it comes to Lister (Pro or not) - probably security concerns. You might want to take a look at @bernhard's RockGrid module instead. A bit more work initially than just creating a new Lister Pro instance, but you're totally free to list / select / query whatever you like. 1 1 Link to comment Share on other sites More sharing options...
cst989 Posted November 20, 2019 Author Share Posted November 20, 2019 Yeah I absolutely can narrow it down in other ways, its just that if this worked I would have something I could use on any site without modifying the templates checked each time, or having this extra step to check when finishing a site. I build quite a lot of ProcessWire sites so I'm making templates more often than most! I really appreciate the input though, I will make do with what I have for now. Maybe @ryan could weigh in on this one day ? Link to comment Share on other sites More sharing options...
dragan Posted November 20, 2019 Share Posted November 20, 2019 To increase the chance that Ryan even sees your suggestion, I'd create a post in the Lister Pro forum (feature request). Who knows, maybe with a hook it can be already done somehow today... Link to comment Share on other sites More sharing options...
Robin S Posted November 21, 2019 Share Posted November 21, 2019 @cst989, here is one way you could do it. First create a new Lister bookmark with the columns and sorting set the way you want. It doesn't matter what you set in the filters because we are going to override that in a hook. Take note of the bookmark ID in the URL when you view the bookmark in Lister. Now add the following hook to /site/ready.php, updating the bookmark ID to suit: $wire->addHookBefore('ProcessPageLister::execute', function(HookEvent $event) { /* @var ProcessPageLister $lister */ $lister = $event->object; $bookmark = $event->wire('input')->get('bookmark'); // If executing your specific bookmark if($bookmark === '_1574293851') { // Find the templates that contain the meta_title field $tpls = new TemplatesArray(); foreach($event->wire('templates') as $template) { if($template->flags) continue; // Skip system templates (e.g. repeater templates) if($template->fieldgroup->has('meta_title')) $tpls->add($template); } // Set the defaultSelector for the Lister $lister->defaultSelector = "template=$tpls, meta_title=''"; } }); 1 Link to comment Share on other sites More sharing options...
cst989 Posted November 21, 2019 Author Share Posted November 21, 2019 That looks great @Robin S thanks! Would this work with ListerPro as well? Link to comment Share on other sites More sharing options...
Robin S Posted November 21, 2019 Share Posted November 21, 2019 9 hours ago, cst989 said: Would this work with ListerPro as well? Yes. If you want the hook to apply to a specific Lister Pro instance instead of a bookmark you could do this: $wire->addHookBefore('ProcessPageLister::execute', function(HookEvent $event) { /* @var ProcessPageLister $lister */ $lister = $event->object; // If executing a specific Lister Pro instance if($event->wire('page')->name === 'your-lister-page-name') { // Find the templates that contain the meta_title field $tpls = new TemplatesArray(); foreach($event->wire('templates') as $template) { if($template->flags) continue; // Skip system templates (e.g. repeater templates) if($template->fieldgroup->has('meta_title')) $tpls->add($template); } // Set the defaultSelector for the Lister $lister->defaultSelector = "template=$tpls, meta_title=''"; } }); 1 1 Link to comment Share on other sites More sharing options...
cst989 Posted December 2, 2019 Author Share Posted December 2, 2019 Thank you, I finally got around to doing this. I was able to combine in || $template->fieldgroup->has('meta_description') as well, and left out the , meta_title='' so you can see them all, empty or otherwise. Only minor oddity remaining is that all the filters generated by this script load in an open position, and you get an odd js glitch when you try to close them the first time - but beggars can't be choosers! 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