After finding this answer, I went with:
$template_tree = mytheme_get_template_tree();
$total = count($template_tree); //count the elements in the array
end($template_tree); //set the pointer to the end of the array
$immediate_parent = basename(prev($template_tree)); //get the filename of the penultimate element
Then in a plugin / functions.php
function mytheme_get_template_tree()
{
$included_files = get_included_files();
$stylesheet_dir = str_replace( '\\', "https://wordpress.stackexchange.com/", get_stylesheet_directory() );
$template_dir = str_replace( '\\', "https://wordpress.stackexchange.com/", get_template_directory() );
foreach ( $included_files as $key => $path ) {
$path = str_replace( '\\', "https://wordpress.stackexchange.com/", $path );
if ( FALSE === strpos( $path, $stylesheet_dir ) && FALSE === strpos( $path, $template_dir ) ) {
unset( $included_files[ $key ] );
}
}
return $included_files;
}
Am still interested to hear about alternative approaches though!