Search code examples
google-apps-scriptgoogle-appsgoogle-sites

Is it possible to create Google Sites page along with subpages using Apps Scripts?


Using the method "createWebPage" in the class "Site", I know I could create a page using Apps Scripts. What I want to do is creating subpages to the first page. Using the structure below as an example:

  • Animal
    • dog
      • shihtzu
      • bulldog
    • cat
      • bengal
      • siamese

How do I go about creating this? Anyone who's done something like this, please show me how to get started. Thanks!


Solution

  • Yes, the Page class also has a createWebPage method to allow pages to create pages as children (subpages). So your code would look something like this:

    //...get a site first and then
    var animalPage = mySite.createWebPage("title", "name", "some html");
    var dogPage = animalPage.createWebPage("title", "name", "some html");
    var shihtzuPage = dogPage.createWebPage("title", "name", "some html");
    

    Let us know how you go.