0

I want to keep common resources, such as css and js, in a common google script project and then import them in different projects (web apps)

So, instead of using a local file:


    <?!= HtmlService.createHtmlOutputFromFile('CSS').getContent(); ?>

I want to use an asset from an imported file (Resources > libraries > import project)

1 Answer 1

1

In your library, you need both the shared HTML files as well as functions that will return their content. You can then call those functions in your projects.

Library

Code.gs:

/**
 * Gets the CSS file as HTML and returns its content.
 * @returns {string}
 */
function getCss() {
  return HtmlService.createHtmlOutputFromFile("CSS").getContent();
}

CSS.html

<style>
  p {
    background-color: yellow;
  }
</style>

Project

Code.gs

function doGet() {
  return HtmlService.createTemplateFromFile("Index").evaluate();
}

Index.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <?!= Library.getCss(); ?>
  </head>
  <body>
    <p>Hello</p>
  </body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.