title: Google Script Pass variable to templated HTMLService
body: <p>I have a script which I have published as a web app.  I wanted to change a default setting based on the URL used to run the web app.  I am already opening one of two forms, but on one form, I want to have a radio button selected based on a second passed parameter.  In the server side gs file I have:</p>
  
  <pre><code>function doGet(passed) {
  
    switch(passed.parameter.form) {
      case 'single':
          var result = HtmlService.createTemplateFromFile('Single').evaluate();
          result.setHeight(550);
          result.setWidth(565);
          break;
      case 'grid':
      default:
          var result=HtmlService.createTemplateFromFile('GridView').evaluate();
          result.setHeight(550);
          result.setWidth(1285);
        }
  
    return result;
      }
  </code></pre>
  
  <p>On Google's HTML Service: Templated HTML page there is a section <a href="https://developers.google.com/apps-script/guides/html/templates#pushing_variables_to_templates" rel="nofollow">Pushing variables to templates</a> which seems to be what I want but I can't get it to work.</p>
  
  <p>in my Single.html file I have:</p>
  
  <pre><code>      &lt;body&gt;
           &lt;? if (data === "Ex") { ?&gt; Existing &lt;? } else { ?&gt; New &lt;? } ?&gt;    
         ... &lt;/body&gt;
  </code></pre>
  
  <p>The html portion above is overly simplified and getting this to work will get me to my ends, which is a much larger page with input areas, etc.</p>
  
  <p>In an attempt to get "Existing" to display in the resulting page, I have changed the above code to:</p>
  
  <pre><code>function doGet(passed) {
  
    switch(passed.parameter.form) {
      case 'single':
          var result = HtmlService.createTemplateFromFile('Single');
          result.setHeight(550);
          result.setWidth(565);
          result.data = 'Ex';
          return result.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
          break;
      case 'grid':
      default:
          var result=HtmlService.createTemplateFromFile('GridView').evaluate();
          result.setHeight(550);
          result.setWidth(1285);
  
          return result;
        }
  
      }
  </code></pre>
  
  <p>and get errors </p>
  
  <blockquote>
    <p>TypeError: Cannot find function setHeight in object HtmlTemplate. (line 131, file "Code")</p>
  </blockquote>
  
  <p>Even if I remove the setHeight and setWidth resulting in just have the data as shown on the above referenced page I get errors.</p>
  
  <p>Has anyone passed a variable to a page like this?</p>