include a single menu.html to multiple appscript files

19 views
Skip to first unread message

Wilson Galter

unread,
Sep 12, 2019, 6:01:55 PM9/12/19
to Google Apps Script Community
Hello,
I have included stylesheet and javacript file references to several of my html files successfully in the past. Recently I'm in need to included a menu file to many pages, but it has been unsuccessful.

I've tried to do this :

CODE.gs
function include(Menu) {
 
return HtmlService.createTemplateFromFile(Menu)
   
.evaluate()
   
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
   
.getContent();
 
}



and used this in all of the other pages as needed.
<?!= include('Menu'); ?>




My menu file is formated as Menu.html


<nav id="menu-wrap"><div id="menu-trigger">Menu</div>    

 
<ul id="menu">
 
<li><a onclick="google.script.run.showControlPanel()">Home</a></li>


 
<li>
 
<a href="">Categories</a>
 
<ul>
 
<li>
 
<a href="">Por Funcionarios</a>
 
<ul>
        More Code...
</ul>
</nav>


            Thank you for the help in advance
Wilson


Wilson Galter

unread,
Sep 12, 2019, 6:13:53 PM9/12/19
to Google Apps Script Community
I think that I just figured it out. But it may not be recommended practice
I just used this in all of the files I need the menu in and it worked.

 
<?!= HtmlService.createHtmlOutputFromFile('Menu').getContent(); ?>

Michael O'Shaughnessy

unread,
Sep 12, 2019, 11:26:41 PM9/12/19
to Google Apps Script Community
I think you are close...  I am wondering in your orginal code why you are using "evaluate" when your menu.html has no scripplet tags.  

I have always used this code:
// This is to get the CSS and JS into the HTML page (done using templated HTML and scripplets
function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename).getContent();
}

To get my css and js loaded using scripplets tags like this:

<?!= include('js'); ?>
<?!= include('dbjs'); ?>

I suggest you try changing you original code to "fromFile" and don't "evaluate" and see what happens.
Reply all
Reply to author
Forward
0 new messages