Pass google script value to html

后端 未结 1 921

I have been looking at various other solutions posted here but none of them seem to work for me.

I\'m trying to pass a variable from my google script (which is orig

相关标签:
1条回答
  • 2020-12-12 05:41

    You are on the right track. Because you've already passed the variable to the HtmlTemplate object, the only remaining step is to use GAS template engine to render it.

    .GS file

    ...
    htmlTemplate.timehtml = time;
    ...
    

    HTML template

       <input type="text" name="time" id="time" value="<?!= timehtml ?>">
    

    More on templated HTML in GAS here https://developers.google.com/apps-script/guides/html/templates

    The reason your code doesn't work is that you are passing the variable by setting the property of the HtmlTemplate object. HtmlTemplate and HtmlOutput objects exist only in the context of GAS Script Editor runtime. Your browser ends up getting the HTML string which it then parses into DOM elements and renders. At that stage, any GAS-related context is lost, with your locally installed browser software being the new runtime environment for your code. That's the reason why you can't reference the 'timehtml' variable.

    0 讨论(0)
提交回复
热议问题