Alan Wells
Alan Wells

Reputation: 31300

Set up seperate CSS files for Apps Script UI Service

With Apps Script UI service, the CSS Styling can be set with the setStyleAttributes() method of the various classes.

setStyleAttributes

Multiple CSS style attributes can be set at the same time with setStyleAttributes(). The CSS style settings can be put into an key:value object assigned to a variable, and then the variable can be used in the setStyleAttributes method.

var cssHome = {"color":"red", "cursor": "pointer", "textDecoration" : "underline", "fontSize": "small", "font-family":"Arial Black"}
var menuHome = app.createMenuItem('HOME')
menuHome.setStyleAttributes(cssHome)

Right now all my code and variables are in one .gs file, and everything is in the doGet function. Is there a way to put the CSS into another file, and call it?

Upvotes: 0

Views: 102

Answers (1)

JSDBroughton
JSDBroughton

Reputation: 4034

If you are happy authoring the CSS as key value pairs you could either wrap them in a separate function and call it at value assignment or you could store in a flat file in Drive and UrlFetch it. Neither solution allows for conventional CSS authoring but does you ask.

As it is for a doGet the former might be preferable. You could reuse this styling across multiple scripts by wrapping in another GS and referencing it as a library.

If you used HtmlService instead of UiService your CSS options are increased by convention.

Upvotes: 1

Related Questions