Invoke app scripts with parameters from classic google site

人盡茶涼 提交于 2019-12-08 14:24:27

Google Apps Script gadget can't include parameters in the gadget settings, instead, add the parameters to the links to the Google Site page

https://sites.google.com/sites/mysite/mypage?par1=A&par2=B

Regarding having several instance of the same Google Apps Script gadget that could be a problem. I think that the better way to proceed is to make copies of your script and make a different set of parameters for each one.

Step by step

  1. Create a site
  2. Create a script
  3. Add the gs code

    In this case the code create a template from a file that has a printlet that shows the Hellow World! if the URL parameter message is equal to true, otherwise it you show undefined.

    function doGet(e) {
      var template = HtmlService.createTemplateFromFile('Index');
      if(e.parameter.message === 'true') template.message = 'Hello World!';
      var output = template.evaluate();
      return output;
    }
    
  4. Create a HTML file and add the HTML code

    <!DOCTYPE html>
    <html>
      <head>
        <base target="_top">
      </head>
      <body>
        <p><strong>Message:</strong>&nbsp;<?!=message?></p>
      </body>
    </html>
    
  5. Publish your web app

  6. Create a page
  7. Insert a Google Apps Script gadget
  8. Save the page
  9. Write the page URL and the required parameters in the browser address box or in a link

    https://sites.google.com/a/rubenrivera.mx/ejemplos/posts/1?message=true

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!