4

How do I load different pages in doGet with HTML Service programmatically? If it is impossible, why GAS editor allows creating different HTML pages?

Rubén
  • 34,714
  • 9
  • 70
  • 166
Andy Leung
  • 65
  • 1
  • 5

1 Answers1

4

If your loading different pages based on parameters passed in the URL you can test for the parameter using

function doGet(e) {
   if (e.parameter.messageID) {   // Simply test if the parm messageID exists

You can always do something like this too

switch (v) {
   case "A":   var t = HtmlService.createTemplateFromFile("A");  break;
   case "B":   var t = HtmlService.createTemplateFromFile("B");  break;
}
return t.evaluate();

And my final option is you can put conditional logic into the template to get different HTML

 // GAS file
 var t = HtmlService.createTemplateFromFile("A");
 var v = "A";   
 t.v = v;  // pass the variable v to the template 
 return t.evaluate();

 // A.html template file
 <? if (v == "A") { ?>
    <b>a bold A</b>
 <? } else { ?>
    <b>not a A but bold anyway </b>
 <? } ?>
user1623237
  • 223
  • 2
  • 6
  • 2
    Thank you. So if I load index.html at first, then how do I reload the doGet in order to reevaluate the condition you have above? – Andy Leung Oct 03 '12 at 12:40