1

I have been scripting a few ways to make my Google site easier to manage by dynamically creating pages. I want to be able to create a directory with links to those pages.

So i was thinking something like...

var page = site.getChildByName("NEW URL");
var link = [page.getUrl()];
page = site.getChildByName("URL TO DIRECTORY").addListItem(link);

...using google apps scripts. Haven't tested this too thoroughly as of yet but it haven't been able to get the links to work in the list. I was hoping to just keep the page template as a normal webpage.

If I went that route would editing the html be the only option? Hopefully there is an easier way.

Any ideas would be great. Thanks!

jkmayne
  • 79
  • 1
  • 9

1 Answers1

1

here is a small test that shows a list of all the pages in your site

function doGet() {
  var app=UiApp.createApplication().setTitle("Directory of this site")
  var mainPanel = app.createAbsolutePanel().setStyleAttributes({background:'beige',padding:'20px'});
  var scroll = app.createScrollPanel().setPixelSize(450,300);
  var site = SitesApp.getSiteByUrl('https://sites.google.com/site/appsscriptexperiments/')
  var pages = site.getAllDescendants()
  var grid = app.createGrid(pages.length,2).setWidth(400)
    for(n=0;n<pages.length;++n){
    grid.setText(n, 0, pages[n].getName()).setWidget(n, 1, app.createAnchor('open', pages[n].getUrl()))
    }
    app.add(mainPanel.add(scroll.add(grid)))
    return app
}

I suppose you know ho to use it in your sitepage but just for info for anyone else : you have to go to manage site > script apps > create a new script > save a version > deploy with appropriate authorizations and finally return to your page and insert it as a gadget (better with a border and a size of 450x300, personal pov ^^) . You can also use it as a standalone webapp using its deploy url.

enter image description here

Serge insas
  • 45,904
  • 7
  • 105
  • 131
  • ahhhh okay so I can just mod this to get the descendants of my dir page. The only thing that worries me is that I am running the page build script in junction with another ui instance so I will have to separate this script to just keep the "grid" update with new pages as they come in. Thank you!! This is going to be a huge help! – jkmayne Jan 18 '13 at 22:55
  • You could as well integrate this snippet in another script as far as the `getAllDescendants` statement comes after any new page is created. Well, I didn't test it in that context but it seems pretty logical (is what we are doing logical ? ^^) – Serge insas Jan 18 '13 at 23:02
  • So I have ran into a bit of a problem with the scrolling functionality. – jkmayne Jan 22 '13 at 20:08
  • When I replace the `var site = SitesApp.getSiteByUrl ` with `var site = SitesApp.getPageByUrl ` in order to make this a directory of just a subpage of my total site. I lose the Scrolling functionality of ScrollPanel. – jkmayne Jan 22 '13 at 20:10
  • Are you sure there are enough rows in the list to have something to scroll through? (I know this is a silly question but who knows? :-) I'll test on my side and see what happens. – Serge insas Jan 22 '13 at 21:52
  • I just tested and, as I suspected, it works exactly the same way... I guess something else must have change on your side. please open a new question if necessary showing your code. – Serge insas Jan 22 '13 at 23:02
  • Will do. You may be right because the list is significantly shorter, I will play with the dimensions and see what happens. Thanks! – jkmayne Jan 23 '13 at 21:11
  • If I make the dimensions of the scroll panel smaller than the list it should invoke the scrolling functionality correct? – jkmayne Jan 23 '13 at 21:47
  • Yes, that's how I made the test too :-) – Serge insas Jan 23 '13 at 22:04
  • Not sure what the deal was but it works now. Had to adjust the Ui instance window height I think.. Thanks again for this it was a huge help! – jkmayne Jan 23 '13 at 23:36