Use wp_head hook on template page

Why not simply create a function, add the action then do the action?

function code_name() {
    // add code here
}
add_action( 'action_name', 'code_name' );

Then inside your template file, simply paste <?php do_action( 'action_name' ); ?>

P.S. You may change the action_name and code_name to whatever you like!