Apps Scripts within Google Sites - google-apps-script

So I might be doing this entirely wrong, but I am trying to create a slideshow based on images stored in a google drive folder that can be easily added (ie by a non-technical person) to a google site.
I created a script that outputs the slideshow using the HTMLService. You can view the working site at https://script.google.com/a/macros/needham.k12.ma.us/s/AKfycbyOyqTr_sEMWRVBn0e0r4NV5083_LwzZSMYwPU-25_xd2m6ZexS/exec?width=300&height=200&folderID=0B-6QUsY0bQG5ZmI4QTl4T1ZQZmc
When I try to insert this script into a google site using the Apps Script Gadget (Screenshot 1) using the link above it appears that the parameters are either lost or ignored (Screenshot 2). When I hard code the parameters into the script, the slideshow loads correctly (Screenshot 3).
Screenshot 1
Screenshot 2
Screenshot 3

You cannot add the parameters to the URL when inserting your script in a Google Site. However, you can pass the parameters to the Site URL utself and the script will pick it up.
For example,
http://sites.google.com/example.com/example-site/example-page?folderID=1235
As for the width and the height, you can adjust them when you insert the script into a Site using controls that Google Sites provides

Same happened to me. My solution was to write a google gadget that iframed my apps script and added fhe necesary parameters.

Related

How do I reference a support file in Google Apps project

Is it possible to use a support file from within the apps script project as a source for iframe in another HTML.
I need to do this as a part of a Web App project in Google Apps Script.
Specifically I need it to work as a menu system which is the same across multiple pages, so that I don't have to repeat the same HTML code over and over again.
Better explained in a picture
Left side menu(buttons) stays the same across pages
There are several ways to accomplish what you are looking (" I don't have to repeat the same HTML code over and over again") but using iframe is not the best way when working with Google Apps Script web applications.
First you have to decide if you want to handle your web application as a multipage or as simple page.
In any case you might find helpful to use templated HTML / scriptlets to pass the code from Google Apps Script .html files to your main html code. If you find yourself scripts hard to start with, then you might use other methods of the HTML Service
Resources
https://developers.google.com/apps-script/guides/html/
https://developers.google.com/apps-script/guides/html/templates
https://developers.google.com/apps-script/reference/html
Related
Use project Javascript and CSS files in a Google Apps Script web app?
Recent related question (no answers at this time, but with comments)
HTML Service: Templated HTML as sidebar
Is it possible to create navigation bar on Google Apps Script?
how to connect a navigation bar (<nav>) with HTML files in google appscript?

Google Sites Drawing Reload

Total noob here with almost zero understanding of Google Apps Script or coding in general.
I was looking for a way to force a reload of a google sites page. This (reload page google apps script) makes it look like that can't be done, so I want to try and reload just the google drawing embedded in the site if possible.
I tried to use a javascript iFrame reload:
window.setInterval("reloadIFrame();", 30000); function reloadIFrame() { document.frames["frameNameHere"].location.reload(); }
But I don't think google sites supports this our I got it wrong somewhere.
I can't figure out what the correct Apps Script would be to force the page to reload(pull from the server) the drawing in question. The code for the drawing looks like this:
img
src="https://www.google.com/chart?chc=sites&cht=d&chdp=sites&chl=%5B%5BGoogle+drawing'%3D20'f%5Cv'a%5C%3D0'10'%3D999'0'dim'%5Cbox1'b%5CF6F6F6'fC%5CF6F6F6'eC%5C0'sk'%5C%5B%2211.30.15%22'%5D'a%5CV%5C%3D12'f%5C%5DV%5Cta%5C%3D10'%3D0'%3D1000'%3D347'dim'%5C%3D10'%3D10'%3D1000'%3D347'vdim'%5Cbox1'b%5Cva%5CF6F6F6'fC%5CC8C8C8'eC%5C'a%5C%5Do%5CLauto'f%5C&sig=0bBZl8MyZOx5b3ykHuUS35Gb8iE"
data-origsrc="1mUFhZeas0mFl52FpqC_EgflRn6P3TixsOxMAXI-_Fgo"
data-type="sketchy"
data-props="align:left;borderTitle:11.30.15;height:350;objectTitle:11.30.15;showBorder:false;showBorderTitle:false;width:1000;wrap:false;" width="1000" height="350"
style="display:block;text-align:left;margin-right:auto;">
It's located in my google drive and I just used the google sites tools to embed it, I didn't code it. The drawing is edited constantly throughout the day and I need the changes to appear while viewing with out requiring a page refresh.
Can anyone help me with where and what code could be used to reload the drawing? Even better would be if I could set an interval (say every 5 minutes) for the refresh. Any help is appreciated.
Thanks
Probably you can create an XML gadget that reloads the Google Sites Page.
Try this one (found quickly)
http://www.k8oms.net/refresh

Updating html of a Google Site's page with multiple blocks using Google Apps Script

I've created a page using "Web Page" template on my Google Sites, and I want to update the page using Google Apps Script. My code looks like this:
var template = HtmlService.createTemplateFromFile('mytemplate'); // meaning 'mytemplate.html'
var content = template.evaluate().getContent();
var site = SitesApp.getSiteByUrl('https://sites.google.com/site/example/');
var page = site.getChildByName('home');
page.setHtmlContent(content);
This works pretty well if the page's layout is "One column (simple)". Now my question is, if I choose one of the other layouts, how can I update each individual blocks using setHtmlContent()? Actually, I tried using "Two column (simple)" layout which has 2 blocks. setHtmlContent() changed the left column's html code and cleared the other column.
EDIT: What I actually wanted to do is to create a page with a gadget and update the page using Google Apps Script. According to this issue tracker https://code.google.com/p/google-apps-script-issues/issues/detail?id=572, it looks like we may encounter some problems when updating such page with setHtmlContent(). So I came up with an idea to create a multiple-column page, place a gadget in a column, and only update the HTML code of the other column with the Script to avoid such issue.
You can also create a Stand Alone Web App with Apps Script, then put an Apps Script Gadget into a Sites page. You can have multiple Apps Script Gadgets. I don't know what is triggering the change of the HTML. For all practical purposes, a Stand Alone Apps Script HTML Service App, is basically the same thing as a web site. You don't have a nice, understandable URL, but that won't show up in the Apps Script Gadget. Google will display a message: "This content was not created by Google"
I don't think you'll be able to inject HTML into multiple columns. You could create HTML that has multiple columns in it, and then add that HTML to the one column. So, you would be creating your own columns in HTML.

Google Apps Script Web App on my Domain

I had built a Google UI Apps Script in my Drive account. It works great.
I would like to embed it on my domain. I know that I can embed it as a gadget on a Google site, but I don't want Google's URL appearing in my website.
I have a word-press site and I would like to embed this UI script into a page/post on my word-press site or create a stand alone page on my domain with this script on it.
Is this possible?
I just don't want my users to be redirected off my site and see the long ugly domain of https://script.google.com/a/macros/*************
Any suggestions?
This isn't currently supported.
See (duplicate) Embedding Google Apps Script WebApp in WordPress Page.
Visit Issue 852 and star it for updates. (There are also some potential work-arounds described in the issue comments.)

URL parameters stripped on Google Sites?

Using Google Apps Script gadget, I can use the parameters of the URL (http://sites.google.com/.../my-page?urlparameter=value&otherurlparameter=value) added to a Google Sites webpage to generate dynamic content.
But if you try to add a link to a page of a Google Site with parameters, and then save your page, the parameters are deleted : http://sites.google.com/.../my-page?urlparameter=value&otherurlparameter=value becomes http://sites.google.com/.../my-page. Same thing when trying to publish a webpage using Apps Script Service SitesApp.Page.setHtmlContent(yourHmtl).
It doesn't happen when using external URLs.
How can we bypass this limitation ?
It's possible to include relative links to pages including parameters.
Example :
in http://sites.google.com/.../home/page-1,
a link like http://sites.google.com/.../home/page-2?urlparameters will be overwritten without parameters but ../page-2?urlparameters won't be.