Jump to content

Exclude pages from find if there's no template file.


Martijn Geerts
 Share

Recommended Posts

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

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

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.

  • Like 1
Link to comment
Share on other sites

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

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 )

  • Like 1
Link to comment
Share on other sites

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>";
}
  • Like 6
Link to comment
Share on other sites

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.  

  • Like 4
Link to comment
Share on other sites

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