Jump to content

Selector for pages without tempalte file


Zeka
 Share

Recommended Posts

Hi.

I am really sorry if my question was answered somewhere already, but i can not find this place)

Is there some selector like " template_file_exists" which will indicate that I am looking only for pages without template file? 

Link to comment
Share on other sites

The state "does a template have an existing templatefile" is never kept anywhere. Even the filename itself is constructed at runtime. So you need to do this a bit more manually.

$all = $templates->getArray();
$withoutFiles = array_filter($all, function(Template $t) {
	try{
		$filename = $t->filename();
	} catch(WireException $e) {
		return null; // Couldn't construct filename, return
	}
	return file_exists($filename);
});
array_walk($withoutFiles, function(Template $t) {
	return $t->id;
});
$pages->find("template=" . implode('|', $withoutFiles);
  • Like 3
Link to comment
Share on other sites

I guess you can use this method to check the existence of a filename:

$page->template->filenameExists();

But it will probably not cover all cases. For example, when there is only one controller-like template for all templates.

And I did not find a selector for that, so only in a foreach loop.

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