Google App Script: how to display google drive files with links to templated HTML

I'm new in both Google App Scripting and JavaScript. So, I'm trying to display the grabbed files from my Google Drive with links however when running displayData(); it's literally showing the link and the title of the file on the page without the actual link in it. Here's picture of the html output.

Here's what I have so far:

Code.gs

function doGet() {
  var output = HtmlService.createTemplateFromFile('Page').evaluate();
  return output;
}

function include(filename){
  return HtmlService.createHtmlOutputFromFile(filename)
  .getContent();
}

function displayData() {
  var dir = 'Somefoldername';
  var foldername = DriveApp.getFoldersByName(dir).next();
  var foldercont = foldername.getFiles();
  var listicon = '<img src="https://drive-thirdparty.googleusercontent.com/16/type/application/vnd.google-apps.document">';
  var file, title, links, list = []; 
  while (contents.hasNext()) {
    file = foldercont.next();
    title = file.getName();
    links = file.getUrl();
    date = file.getDateCreated();
    
    list.push('<tr><td>' + listicon + '<a href ="' + links + '">' + title +'</td></tr>');
  }
  return list;

Page.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <?!= include('Stylesheet'); ?>
  </head>
  <body>
    <div class="doclist">
    <?= displayData(); ?>

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

How would I display the Google Drive file hyperlinks in the html template?

Thank you.



Read more here: https://stackoverflow.com/questions/67943384/google-app-script-how-to-display-google-drive-files-with-links-to-templated-htm

Content Attribution

This content was originally published by Gray Farron at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: