在努力調試,我添加了這個功能Code.gs:
function myFunction() {
Logger.log(HtmlService
.createTemplateFromFile('Page')
.getCode());
}
它就像一個正常的功能,而不是一個Web應用程序運行,並且產生調試輸出。從日誌文件中我的結果:
[17-02-19 04:17:31:492 PST] (function() { var output = HtmlService.initTemplate(); output._ = '<!DOCTYPE html>\n';
output._ = '<html>\n' +
' <head>\n' +
' <base target=\"_top\">\n' +
' '; output._ = include('Stylesheet');
output._ = ' </head>\n';
output._ = ' <body>\n' +
' <h1>Welcome</h1>\n' +
' <p>Please enjoy this helpful script.</p>\n' +
' '; output._ = include('JavaScript');
output._ = ' </body>\n';
output._ = '</html>\n';
/* End of user code */
return output.$out.append('');
})();
我不知道在日誌文件中正確的輸出,但我希望看到的包含文件的內容,而不是行:
' '; output._ = include('Stylesheet');
但是,再一次,我的期望可能是錯誤的。如果你有時間,請你試試這個。
我只是這樣做,看看它是否有效,它確實爲我工作。您是否將其部署爲Web應用程序?如果不嘗試發佈並將其設爲web應用程序,並單擊對話框中的小測試按鈕,也許它也適用於您。我確實注意到它們的文件名全部在鏈接處大寫,但實際上它們不應該被大寫。你可能想看看這方面。看看他們使用的文件,看看他們是如何寫的。 – Cooper
是的,我部署爲一個Web應用程序並使用測試鏈接。是的,我做了正確的文件名。例如 - 在Page.html中它所表示的行中:<?!= include('Stylesheet'); ?>我複製了「樣式表」並粘貼它以命名文件「樣式表」,以確保我沒有髮指紋。我出於同樣的原因複製並粘貼了所有4個文件中的所有代碼。 –
在JavaScript.html中添加的事件偵聽器未執行。如果包含Stylesheet.html,那麼文本就沒有什麼綠色。 –