HtmlService模板的服务器错误,调试没有显示任何内容

时间:2012-09-07 10:36:28

标签: google-apps-script

我正在尝试评估的应用脚本项目中有一个HTML模板。我一直收到服务器错误(不是很有用),但在调试时我找不到任何东西。我尝试了getCode()的运行结果,但没有错误。然后我也运行了输出。$ out.getContent()(如此处所述https://developers.google.com/apps-script/html_service),它给出了预期的html输出。

我会附加HTML文件,但它包含很多变量,我在创建带有错误的精简版时遇到了麻烦。我希望有人知道调试这些文件的更好或正确的方法。

编辑:无论如何,这是文件,

html文件:

<html>
  <body>
    <form action="https://script.google.com/macros/s/AKfycbxHQDJoAtAjBF9uIctvmxBHv-QVpYf6f15UZf8aAnAh_1U_PzU/exec" method="POST" id="mail-form">
      <table>
        <tr style="background-color: #392303; font-size: large; line-height: 30px;">
          <th>
            <a href="<?= info.profile ?>" style="color: #e06c01; font-weight: lighter;"><?= userForm.userName ?></a>
          </th> 
          <th colspan="3"> 
            <div width="250px" style="color: #e06c01; font-weight: lighter; float: left; text-indent: 10px;"><?= userForm.experience ?></div> 
            <div style="color: #FFFFFF; background-color: <?= userForm.pastColor ?>; border: 1px solid white; width: 28px; height: 28px; float: right;" title="<?= userForm.pastApplications ?>">
              <center><?= userForm.pastNumber ?></center> 
            </div>
          </th> 
        </tr>
        <tr style="background-color: #9c9181"> 
          <td width="100">
            <center><p style="font-size:small; top: 5px; margin-bottom: 3px;">Thanks meter: <?= info.thanks ?></p></center> 
            <center><img alt="" src="" style="margin-bottom: 10px;"/></center> 
            <center><img src="<?= info.avatar ?>" style="height: 60px; margin-bottom: 10px;" /></center> 
            <center><p style="font-size:small; margin-bottom: 3px; margin-top: 3px;">Posts: <?= info.totalPosts ?></p></center> 
            <center><p style="font-size:small; margin-bottom: 3px; margin-top: 3px;">Per day: <?= info.postsPerDay ?></p></center> 
            <center><p style="font-size:small; margin-bottom: 3px; margin-top: 3px;">Join date: <?= info.joinDate ?></p></center> 
            <center><p style="font-size:small; margin-bottom: 3px; margin-top: 3px;">Last activity: <?= info.activity ?></p></center>
          </td> 
          <td>
            <center><?= userForm.onSite ?></center>
          </td> 
          <td>
            <center><?= userForm.tools + '\n' + '\n' + userForm.theHardPart ?></center>
          </td> 
          <td width="100">
            <center><?= userForm.development ?></center>
          </td> 
        </tr>

        <tr style="background-color: #392303; font-size: large; line-height: 30px;">
          <td colspan="4" style="color: #e06c01; font-weight: lighter; text-indent: 10px;">Review</td>
        </tr>

        <tr style="background-color: #9c9181">
          <td colspan="1" valign="top">
            <label><input type="radio" name="review" value="approved" id="review_1">Accept</label>
          </td>
          <td colspan="1" valign="top">
            <label><input type="radio" name="review" value="rejected" id="review_2">Reject</label><br><br>
            <label><b>Reason(s) for user</b></label><br>
            <label><input type="checkbox" name="reason" value="Reason1" id="requirements">Reason1</label><br>
            <label><input type="checkbox" name="reason" value="Reason2" id="requirements">Reason2</label><br>
            <label><input type="checkbox" name="reason" value="Reason3" id="requirements">Reason</label><br>
            <label><input type="checkbox" name="reason" value="Reason4" id="requirements">Reason4</label><br>
            <label><input type="checkbox" name="reason" value="Reason5" id="requirements">Reason5</label><br>
            <label><input type="checkbox" name="reason" value="Reason6" id="requirements">Reason6</label><br>
          </td>
          <td colspan="1" style="text-indent: 3px;">
            <label><b>Feedback</b></label><br>
            <label><i>Rejections:</i> <b>WARNING</b> users will see this</label><br>
            <label><i>Approvals:</i> only for us</label><br>
            <textarea name="comments" rows="10" cols="35" id="comments"></textarea>
          </td>
        </tr>        
      </table>

      <input type="hidden" name="userName" id="userName" value="<?= userForm.userName ?>"/>
      <input type="hidden" name="reviewerName" id="reviewerName" value="<?= userForm.reviewer ?>"/>
      <input type="hidden" name="link" id="link" value="<?= info.profile ?>"/>
      <input type="hidden" name="row" id="row" value="<?= userForm.row ?>"/>
      <input type="hidden" name="hash" id="hash" value="<?= userForm.hash ?>"/>

      <div>
        <div style="float: left;">
          <input type="submit" name="submit" id="submit" value="Submit">
        </div>
        <div style="float: right;">
          <a href="mailto:<?= mailTo ?>?subject=<?= subject ?>&body=<?= body ?>"> 
            <b>Consult</b>
          </a>
        </div>
      </div>

    </form>
  </body>
</html>

脚本的相关部分:

  var htmlTemplate = HtmlService.createTemplateFromFile('DC Form');
  htmlTemplate.userForm = userForm;
  htmlTemplate.info = info;
  htmlTemplate.mailTo = mailTo;
  htmlTemplate.subject = 'CONSULT: ' + userForm.userName;
  htmlTemplate.body = 'Profile link: ' + userForm.profile + '\n' + '\n';
  var code = htmlTemplate.getCode();
  Logger.log(code);
  var html = htmlTemplate.evaluate().getContent();

任何事情都会受到赞赏,

微米。奥兰哲

编辑:

使用Caja Playground后,我在此行中发现错误:

<div style="color: #FFFFFF; background-color: <?= userForm.pastColor ?>; border: 1px solid white; width: 28px; height: 28px; float: right;" title="<?= userForm.pastApplications ?>">

可能是不支持在属性中使用scriptlet吗?

2 个答案:

答案 0 :(得分:0)

在没有触及您的html的情况下,我尝试了.gs文件的这个轻微变体:

function doGet() {
  var htmlTemplate = HtmlService.createTemplateFromFile('DC Form');
  var userForm = {userName: 'userName', profile: 'profile'};
  htmlTemplate.userForm = userForm;
  htmlTemplate.info = "info";
  htmlTemplate.mailTo = "mailTo";
  htmlTemplate.subject = 'CONSULT: ' + userForm.userName;
  htmlTemplate.body = 'Profile link: ' + userForm.profile + '\n' + '\n';
  var code = htmlTemplate.getCode();
  Logger.log(code);
  return htmlTemplate.evaluate();
}

这对我来说很好。我怀疑你的变量中的一个值出了问题。

答案 1 :(得分:0)

那么,看起来宽度属性中的'px'的简单缺失是导致所有这些麻烦的原因。

<td width="100">

定位相当困难,因为错误只出现在某些条件下,可能只有当大小不匹配时才会出现。这就是为什么Corey G.虽然它必须是变量,因为变量必须具有一定长度才能触发宽度误差。头疼不已。