Here's one demo suggestion:
add_action( 'admin_enqueue_scripts', function()
{
wp_enqueue_script( 'my-script', '/my-script.js', ['underscore', 'backbone'], '1.0' );
wp_add_inline_script( 'my-script', 'alert("hello world");' );
// Add our template
if( function_exists( 'wpse_add_inline_tmpl' ) )
wpse_add_inline_tmpl(
$handle = 'my-script',
$id = 'my-tmpl',
$tmpl = '<div class="section intro">{{{ data.section.intro }}}</div>'
);
} );
where we define our custom wpse_add_inline_tmpl()
function as:
function wpse_add_inline_tmpl( $handle, $id, $tmpl )
{
static $data = [];
$data[$handle][$id] = $tmpl;
add_filter(
'script_loader_tag',
function( $tag, $hndl, $src ) use ( &$data, $handle, $id )
{
if( isset( $data[$hndl][$id] ) )
$tag .= sprintf(
"<script type='text-template' id='%s'>\n%s\n</script>",
esc_attr( $_id ),
$data[$hndl][$id]
);
return $tag;
},
10, 3 );
}
Here we use the script_loader_tag
filter to inject the template code and use both the handle and id to reference it.
Hope you can test this further and modify to your needs. Writing this as a class might be a better approach ;-)