0

我正在尝试评估的应用程序脚本项目中有一个 HTML 模板。我不断收到服务器错误(不是很有帮助),但在调试时我找不到任何东西。我尝试了 getCode() 的运行结果,但那里没有错误。然后我还运行了 output.$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();

任何事情都会不胜感激,

M·奥兰杰

编辑:

使用 Caja Playground 后,我在这一行中发现了一个错误:

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

难道是不支持在属性中使用 scriptlet 吗?

4

2 回答 2

0

Well then, it looks like a simple missing of 'px' in the width attribute was the cause of all this trouble.

<td width="100">

It is fairly hard to locate as the error only appeared in certain conditions, probably only when that the size didn't match whatever it was. This would be why Corey G. though it had to be the variables, as the variables had to be of a certain length to trigger that width error. Headaches gone.

于 2012-09-12T00:19:31.380 回答
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();
}

这对我来说很好。我怀疑您的变量中的某个值有问题。

于 2012-09-07T20:59:01.250 回答