How to pass variable from Code.gs to included script snippet

So I understand that to put a variable in my HTML template I need to do

var html = HtmlService.createTemplateFromFile('Index')    
html.data = data
html = html.evaluate();

and then call it in the HTML with

<?= data ?>

But then if I include a script tag snippet with (in the Code.gs file)

function include(filename) {
   return HtmlService.createHtmlOutputFromFile(filename)
   .getContent();
}

and then include my script snippet in the HTML with

<?!= include('DataHandler') ?>

How do I call that data variable in the DataHandler script?

57 thoughts on “How to pass variable from Code.gs to included script snippet”

Leave a Comment