Simply returning a google scripting function results in an HTML template

I've created a couple of simple functions that return cell values ​​in google scripts. I also created a simple HTML template file and tried Google HTML service documentation ! But my HTML template output still doesn't work for me.

First, my JS is in my .GS file:

function doGet() {
  return HtmlService.createTemplateFromFile('TemplateName').evaluate();
}

function getStarData2() {
  var ss = SpreadsheetApp.openById("key in here").getRange("A2").getValue();
  //Logger.log(ss);
  return ss;
}

      

And my HTML:

...<span><? getStarData2(); ?></span>...

      

I've tried a lot of different things to get it to work, however I find that it either starts but doesn't show or start, or it returns many different errors depending on what I'm trying to accomplish.

I would suggest that this is a very simple solution for all of you experts, so your help is greatly appreciated.

+3


source to share


1 answer


Try using <?= getStarData2(); ?>

instead <? getStarData2() ?>

.



This equals sign basically says "Run this function and then print whatever comes back here." Otherwise, you just run this function and do nothing with the result.

+1


source







All Articles