2016-09-10 10 views
0

HTMLOutの前にdoGet()のhtmlファイルを変更する必要があります。しかし、htmlファイルには<?!=include('css').getContent();?>があり、実行できず、HTMLテキストの一部になります。あなたの助けに感謝?ここにコードがあります。ここでGoogle Apps ScriptのHTMLOutputの前にhtmlファイルを変更する方法

function doGet(e) { 
    var landingPage; 
    landingPage=e.parameter.page ||'index'; 
    var html=HtmlService.createHtmlOutputFromFile(landingPage); 

    var content=html.getContent(); 
    content=content.replace("%%ToBeChanged%%","New Value"); 
    var html2=HtmlService.createTemplate(content); 
    return html2.evaluate() 
    .setTitle('testing Website') 
    .addMetaTag('viewport', 'width=device-width, initial-scale=1') 
} 

あなただけのいくつかのCSSとJavaScriptでページをロードしようとしている場合は、プロジェクト

<!doctype html> 
<html> 
<head> 
<meta charset="UTF-8" /> 

    <title>TITLE</title> 

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

</head> 
<body> 
    <form> 
    <input type='text' value='##ToBeChanged##'> 
    </form> 
</body> 
</html> 
+0

スクリプトレットには、関数名 'include()'があります。 'function include(){return theHtml} 'の.gsサーバー側のコードは表示されません。ビューメニューの「Execution Transcript」をコードが実行され、印刷の下部が見えます。失敗した行番号はありますか? –

答えて

0

中のindex.htmlです。あなたのHTML文書でHTMLServiceを呼びたくはありません。試してみてくださいthis-

Code.gs-

function doGet() { 
    var template = HtmlService.createTemplateFromFile('LandingPage'); 
    return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME); 
} 

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

index.html-

<head> 
<?!= include("StyleSheet"); ?> 
</head> 

お知らせdoGetメソッドの機能は.create TemplateFromFile()、およびない.createHtml OutputFromFile言います。 OutputFromFileは基本的にファイルからデータを取得しますが、処理しません。つまり、StyleSheetまたはJavaScriptファイルをレンダリングまたは組み込みません。

Google AppsスクリプトのドキュメントBest Practicesの設定方法の詳細については、こちらをご覧ください。

私はそれが役に立ちそうです。

関連する問題