OJNSim
OJNSim

Reputation: 798

call google app script htmlservice.createTemplateFromFile(file) with file located on sub folder

On a side bar google app script htmlservice.createTemplateFromFile(file) is used to launch the side bar by user request.

When the html file (the client html file) is located on the root folder, all works smoothly.

I want to rearrange the project files into several subfolders. I'm using visual studio code and clasp push to push changes to server.

Everything is ok, except with the file location. When moving the file, I can not find the way to supply the right path.

for example: before rearrange two files (and others) were on the google editor.

after moving to subfolder and pushing to server, as the editor does not support sub folders it is reflected with the files names so:

I also moved the server js (gs in google editor) to the same folder

Code in server to launch side bar

function launchSideBar(){    
    //try obvious
    let file = "client"; // #1
    file = "./client"; // #2
    
    //like it displays in editor
    file = ".subFolder/client"; // #3
    
    /*maybe server is launched from root, 
      although it also resides on sun folder, so supply 
      relative path from root, like for other files (css,ims etc)
    */
    file = "./subFolder/client"; // #4

    let output = 
        HtmlService.createHtmlOutputFromFile(file);

    //launch
    SpreadsheetApp.getUi() 
      .showSidebar(output);
    
} 

you can see the 4 options I have tried (of course only one different option was not commented each time)

When trying to display the side bar from the sheet added menu item, there is an error message

Exception: No HTML file named subFolder/client was found.  

each time file name is different of course.

server is recognized automatically although also moved.

Ideas?

Upvotes: 0

Views: 719

Answers (1)

TheAddonDepot
TheAddonDepot

Reputation: 8964

Try using file = "subFolder/client" instead.

Upvotes: 2

Related Questions