0

Hi i was wondering if this is the expected behaviour:

<html>
  <head>
  </head>
  <body>
    <?if(a){
      Logger.log("a ="+a)?>
      <table>
        <tr>
          <th>First Name</th>
          <th>Last Name</th>
          <th>Id</th>
        </tr>
        <tr>
          <td><input type='text' name=firstName id='firstNameToEdit' /></td>
          <td><input type='text' name=lastName id='lastNameToEdit' /></td>
          <td><label id='down_id'></label></td>
        </tr>
      </table>
    <?}else{Logger.log("a="+a)}?>
  </body>  
</html>

when a is defined i get the value of the a in the log and everythings shows up as expected but when i leave the a undefined the execution seems to stop at if(a) and log shows nothing.

I serve the html like this:

  var t = HtmlService.createTemplateFromFile('test');
  return t.evaluate();

When i serve it this way:

  var t = HtmlService.createTemplateFromFile('test');
  t.a = b;
  return t.evaluate();

where (b:{undefined,null}) then if i log the value of a inside the html template i get that a=null (in both cases). It seems that you can't have an undefined variable inside a template.

P.S. i would really appreciate a way to turn off auto identation in the editor

1 Answer 1

1

If you run the doGet() method in the editor you should see the error:

ReferenceError: "a" is not defined.

In JavaScript you can't reference a variable that doesn't exist. To work around this you can change the if case to:

<? if (this.a) {

Since this is always defined as the current object/scope.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.