Custom template not working for existing pages [closed]

as a solution, you can fully automate the selection of a template for a group of pages using slug names:

add_filter('request', function( $vars ) {

    $slug =  explode("https://wordpress.stackexchange.com/", explode('?', $_SERVER['REQUEST_URI'])[0]);

    array_pop ($slug);

    $temp_base = "...first_part_template_name...";
    $temp_slug = array_pop ($slug);

    if (file_exists(get_template_directory()."https://wordpress.stackexchange.com/".$template.'-'.$temp_cat.'.php')) {
        get_template_part( $temp_base, $temp_slug );
    } 
}