Martijn Geerts Posted January 16, 2014 Share Posted January 16, 2014 Would be great if pages without template file could be excluded from a search. // now I end up doing this, but obviously this doesn't work well for other situations foreach($items as $item) { if(!$item->template->filenameExists()) continue; // do stuff } Link to comment Share on other sites More sharing options...
Soma Posted January 16, 2014 Share Posted January 16, 2014 I don't think that's really possible with a db query and would if added add overhead. What if you just specify templates in the selector you know have a template file? Link to comment Share on other sites More sharing options...
Martijn Geerts Posted January 16, 2014 Author Share Posted January 16, 2014 You have a valid point, but still it's kinda weird that an invisible page will be found with a default search. Link to comment Share on other sites More sharing options...
Soma Posted January 16, 2014 Share Posted January 16, 2014 A page with a template that has no template file doesn't implicate it's not visible. Maybe it's rendered via urlSegments etc. Or what do you mean with invisible? If it shouldn't be found you would make them hidden or don't give access via template access settings, then it won't be found. Link to comment Share on other sites More sharing options...
Martijn Geerts Posted January 16, 2014 Author Share Posted January 16, 2014 I don't get what you say here: Maybe it's rendered via urlSegments etc If there's no file, there's nothing you can render. What I mean, in the admin: [ home ] | `-- no templateFile, Invisible [edit] // notice, no view button, so hidden. (assumed, correct) | `-- basic-page, Cars [edit][view] | `-- basic-page, Bikes [edit][view] | `-- basic-page, Houyse [edit][view] $all = $pages->find("parent=1"); $all, includes the invisible page. // For me it makes more sence, that the page with no template is excluded from find same as hidden and unpublished Link to comment Share on other sites More sharing options...
Soma Posted January 16, 2014 Share Posted January 16, 2014 What I mean is you can render data of a page even if it has no template file. And what is wrong with excluding them by its template? Or in the find or when doing a foreach? What "obviously" doesn't work for other situations? if(!$p->viewable()) continue or simply by using template access "make" it not viewable? or by making them hidden in the tree? Then you could do a find and don't have them included. 1 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted January 16, 2014 Author Share Posted January 16, 2014 For me it's quite confusing when a page is found, but accessing by URL throws a 404. The reason not showing the view button next to the page in the admin is for this reason I guess. Nevertheless, this is a feature request. Link to comment Share on other sites More sharing options...
tiagoroldao Posted January 16, 2014 Share Posted January 16, 2014 It seems too much of a case-to-case thing here - if I was to use a "tag" Template, for instance, that had no template file (as I many times do, as I handle tag/date/search based page viewing on a parent template, generally), it would be terrible to have something like this enforced. If a flag is what is needed, a global boolean value would do the trick. But assuming any $pages->find() would not return file-less pages seems to me to do more harm than good. Link to comment Share on other sites More sharing options...
Martijn Geerts Posted January 16, 2014 Author Share Posted January 16, 2014 Unless you're doing pagination and want it to be acurate for example. And the other way around doesn't work eighter. You can't exclude if you want. A thing mentioned by Soma ( overhead ) second post, is a reason a good reason for not being available to exclude those in a selector. ( ps I do love these discussions, these discussion make us think. I really appreciate the response from Soma & you here ) 1 Link to comment Share on other sites More sharing options...
Soma Posted January 16, 2014 Share Posted January 16, 2014 This viewable check is something done on runtime and not on db level. Here an example to do what you want: $excl_tpls = "template!="; foreach($templates as $tpl){ if($tpl->filenameExists()) continue; $excl_tpls .= "$tpl->name|"; } $excl_tpls = rtrim($excl_tpls,"|"); foreach($pages->find("parent=1, $excl_tpls") as $p){ $content .= "<p>{$p->title}</p>"; } 6 Link to comment Share on other sites More sharing options...
ryan Posted January 18, 2014 Share Posted January 18, 2014 It wouldn't be safe to exclude pages without template files from most find()s as that would be making the assumption that all find()s are for presenting navigation or search results to a user. PW makes no assumptions about what you are using the data for, so couldn't safely exclude pages based on that factor. If we were to implement something for this in the core in the future, we'd probably do it with a new selector option like "template_file_exists=1" or something along those lines. But if you've got pages without template files showing up in your search results, it might also be good to look at whether your search might need to be made more specific, or if your pages with no template file should be excluded with an access controlled parent. But I'll keep marinating on this template_file_exists option for selectors, as it may be a worthwhile addition. 4 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