nghi Posted February 2, 2016 Share Posted February 2, 2016 Just wondering if this exist...? $pages->find("select all templates that don't have an existing template file"); $page->children("same sort of selector top"); Link to comment Share on other sites More sharing options...
BitPoet Posted February 2, 2016 Share Posted February 2, 2016 It doesn't. Whether a template file matching the name of the template (or the alternative name in the template config) is in fact present in the file system isn't stored in the database. You could assemble a list of all templates without file and put that into a selector though: $missing = array(); foreach($templates->find("flags!={template::flagSystem}") as $tpl) { if(! $tpl->filenameExists()) $missing[] = $tpl->name; } // Now you can get all pages with missing template file: $pages->find("template=" . implode("|", $missing)); // Or just children $page->children("template=" . implode("|", $missing)); 7 Link to comment Share on other sites More sharing options...
Gadgetto Posted March 27, 2019 Share Posted March 27, 2019 On 2/2/2016 at 6:09 PM, BitPoet said: It doesn't. Whether a template file matching the name of the template (or the alternative name in the template config) is in fact present in the file system isn't stored in the database. You could assemble a list of all templates without file and put that into a selector though: $missing = array(); foreach($templates->find("flags!={template::flagSystem}") as $tpl) { if(! $tpl->filenameExists()) $missing[] = $tpl->name; } // Now you can get all pages with missing template file: $pages->find("template=" . implode("|", $missing)); // Or just children $page->children("template=" . implode("|", $missing)); Sorry, just stumbled across that older post searching for an answer regarding templates selectors... I'm looking for a method to select all templates except system templates. This part from your code above doesn't work here: $templates->find("flags!={template::flagSystem}") it could only get it to work like this: $templates->find('flags!=' . Template::flagSystem) But what's more important is: "flags" is a bitmask value, is it OK to simply compare it in a selector? Link to comment Share on other sites More sharing options...
LostKobrakai Posted March 27, 2019 Share Posted March 27, 2019 Flags are only for internal use. You most likely cannot use them in selectors. Also you don't need to try to be efficient when selecting templates, as all templates are loaded as part of the processwire bootstrapping process, so you can simply iterate $templates and select only non system templates without using a selector. Everything's in memory anyways. 5 Link to comment Share on other sites More sharing options...
BitPoet Posted March 27, 2019 Share Posted March 27, 2019 3 hours ago, Gadgetto said: But what's more important is: "flags" is a bitmask value, is it OK to simply compare it in a selector? In Template context, is (currently) is, since the only flag currently defined for templates is the system flag. But @LostKobrakai is correct that iterating $templates isn't really a hardship (and likely faster anyway since there are no selectors parse). 1 Link to comment Share on other sites More sharing options...
Gadgetto Posted March 27, 2019 Share Posted March 27, 2019 4 hours ago, LostKobrakai said: Flags are only for internal use. You most likely cannot use them in selectors. Also you don't need to try to be efficient when selecting templates, as all templates are loaded as part of the processwire bootstrapping process, so you can simply iterate $templates and select only non system templates without using a selector. Everything's in memory anyways. Ok, thanks! Solved it like this: /** * Get all templates except system templates (name => label) * * @return WireArray $templates * */ public function getTemplates() { $templates = new WireArray(); foreach ($this->wire('templates') as $t) { if (!($t->flags & Template::flagSystem)) { $templates->add($t); } } return $templates; } 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