collect(['PostTypes'])
->each(function ($folder, $file) {
if (! locate_template($file = "app/{$folder}/case-studies.php", true, true)) {
wp_die(
/* translators: %s is replaced with the relative file path */
sprintf(__('Error locating <code>%s</code> for inclusion.', 'sage'), $file)
);
}
});
But then, how would you make the ‘file’ dynamic? That’s the error I get when I replace case-studies with {$file}: Error locating app/PostTypes/0.php for inclusion..
The code that ships with Sage that you’ve screenshotted is only intended to load files, it has no built in capacity to understand directories, or to load files from a directory. It iterates over an array of strings, concatenates a string in each iteration, and tries to load the file at the resulting path. If you want more complex behavior than that, you’ll need to implement it yourself.