Search code examples
google-apps-scriptgoogle-apps

Google apps script html service based news (announcement) display


I would like to display 2 latest news post from my google site's news announcement page. I am using the following codes- index.html

<html>
  <body>
    <div>
<?

 var site = SitesApp.getSite("google.com", "mysite1");

 var page = site.getChildByName("news");
 var announcements = page.getAnnouncements({ start: 0,
                                             max: 2,
                                             includeDrafts: false,
                                             includeDeleted: false
                                              });

 for(var i in announcements) {
   Logger.log(announcements[i].getHtmlContent());
 }

?>
    </div>
  </body>
</html>

script:

function doGet(e) {
  var template = HtmlService.createTemplateFromFile('Index').evaluate();
}

when I am adding this script to my site I am getting the following error. "The script completed but did not return anything."

Please help me to correct the error and if possible a solution. Thank you.


Solution

  • doGet is not returning anything. Look at the official htmlService help. The samples show you what to return.