PHP theme function to return list of pages with specific template

First post, so be gentle!

I want to create a select (dropdown) in admin with a list of pages which have the specific template ‘parish’, i.e. with the pagename ‘parish.md’.

I have created a theme (incubator) and in and in incubator.phpI have a function which I want to return the array of page slugs/titles which I can use in @data-options for the select ('@data-options': '\Grav\Theme\Incubator::getParishes')

I am missing something - I know the function below is all wrong but how do I achieve what I want?

public static function getParishes()
{
		$collection = new Collection();
		$collection = $collection->ofType('parish')->order('date', 'desc');
		//dump($collection);
		$titles = [];

		foreach ($collection as $page) {
		    $titles[$page->slug()] = $page->title();
		}
		return $titles;
}

$collection appears to just contain everything. That said I don’t even know how to iterate through $collection!

Thanks

Nick

This works as a workaround:

class Incubator extends Theme
{
    // Access plugin events in this class
	
	public static function getDioceses()
	    {
			$page = Grav::instance()['page'];
			$collections = $page->evaluate(['@root.descendants'])->ofType('parish');
			$titles = [];
			foreach ($collections as $k=>$v) {
				$titles[$v->slug()] = $v->title();
			}
			return $titles;
		}
}