Title1

Title2

Title3

9-6 渲染樣版函式

  1. ScriptApp.getService().getUrl();//取得網頁應用程式網址

物件設值:
let obj = {};

obj['title'] = "育將電腦工作室";

obj['content'] = "123";

物件取值:

obj[title] 

obj.title


/* ==========================
  渲染
  render('index', {content: '網頁內容'}, '首頁');
============================*/
function render(file, argsObject, title){
  var tmp = HtmlService.createTemplateFromFile(file);
  if(argsObject){
    for(i in argsObject){
      tmp[i] = argsObject[i];
    }
  }
  return tmp.evaluate().setTitle(title).setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL).addMetaTag('viewport', 'width=device-width, initial-scale=1');
}
 
  /*======================================
    渲染樣版&子樣版
    file: 樣版(主檔名即可)
    argsObject: 參數
    title: 有值=>主樣板 空值=>子樣板
  ======================================*/
  static render(file, argsObject, title=''){
    let tmp = HtmlService.createTemplateFromFile(file);
    if(argsObject){
      for(let i in argsObject){
        tmp[i] = argsObject[i];
      }
    }
    if(title){
      return tmp.evaluate().setTitle(title).setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL).addMetaTag('viewport', 'width=device-width, initial-scale=1');
    }else{
      return tmp.evaluate().getContent();
    }
  }