wordpress插件的自定义模板

I am searching a solution to add a custom template for plugin on short code. But I am unable to do it successfully.

I have made a template folder in my plugins folder and put a custom template in it. I want to show this template by putting a short code. For this I have written following piece of code.

function wp_parse_login()
{
    add_action('template_redirect', 'my_template');
    function my_template()
    {
        include ('template/login.php');
        exit;
    }
}
add_shortcode('parse_login_page','wp_parse_login');

but it's not working. I have include this file to my main plugin file. I think I am leaving some hooks.

Here an adapted example from WordPress Codex

function wp_parse_login() {
    ob_start();
    include ('template/login.php');
    return ob_get_clean();
}
add_shortcode('parse_login_page','wp_parse_login');

You first set a page template in DB Like:

$table_post_meta = $wpdb->prefix.'postmeta';

$meta_data = array(
    'post_id'       =>  $post_id, (Get dynamically post id of a page)
    'meta_key'      =>  '_wp_page_template',
    'meta_value'    =>  'template/login.php' (Give the file path)
);
$wpdb->insert($table_post_meta,$meta_data) or die(mysql_error());

The you write in your this code in your template page:

function wp_parse_login() {
    ob_start();
    include ('template/login.php');
    return ob_get_clean();
}
add_shortcode('parse_login_page','wp_parse_login');

Hope you find your solution.