Class Page

Page

A Page on a Google Site.

Methods

MethodReturn typeBrief description
addColumn(name)ColumnAdd a new column to the list.
addHostedAttachment(blob)AttachmentAdd an attachment to the page.
addHostedAttachment(blob, description)AttachmentAdd an attachment to the page.
addListItem(values)ListItemAdd a list item to the list.
addWebAttachment(title, description, url)AttachmentAdd a web attachment to the page.
createAnnouncement(title, html)PageCreate an announcements for this page.
createAnnouncement(title, html, asDraft)PageCreate an announcements for this page.
createAnnouncementsPage(title, name, html)PageCreate a new announcements page.
createFileCabinetPage(title, name, html)PageCreate a new file-cabinet page.
createListPage(title, name, html, columnNames)PageCreate a new list page.
createPageFromTemplate(title, name, template)PageCreate a new page from a template.
createWebPage(title, name, html)PageCreate a new web page.
deletePage()voidDeletes this page.
getAllDescendants()Page[]Gets an array of descendant pages (direct and indirect), up to a limit of 200 pages.
getAllDescendants(options)Page[]Gets an array of descendant pages, with optional advanced arguments.
getAnnouncements()Page[]Get the announcements for this page.
getAnnouncements(optOptions)Page[]Get the announcements for this page.
getAttachments()Attachment[]Get the attachments for this page.
getAttachments(optOptions)Attachment[]Get the attachments for this page.
getAuthors()String[]Get the emails of the authors of the page
getChildByName(name)PageGets a particular child page.
getChildren()Page[]Gets an array of child pages, up to a limit of 200 pages.
getChildren(options)Page[]Gets an array of child pages, with optional advanced arguments.
getColumns()Column[]Get the columns for the list.
getDatePublished()DateReturn the date this page was first published.
getHtmlContent()StringGet the HTML content of the page.
getIsDraft()BooleanReturns whether the page is in draft mode.
getLastEdited()DateReturn the last edit date, which includes only content edits.
getLastUpdated()DateReturn the last updated date, which includes non-content changes like moving.
getListItems()ListItem[]Get the list items for the list.
getListItems(optOptions)ListItem[]Get the list items for the list.
getName()StringReturn the page's name.
getPageType()PageTypeReturn the type of this page as a SitesApp.PageType enum.
getParent()PageReturn the parent of this page.
getTextContent()StringReturns the plain-text page content.
getTitle()StringReturn the page's title.
getUrl()StringGet the url of the page.
isDeleted()BooleanReturns whether a page has been deleted.
isTemplate()BooleanReturns whether this page is a copyable template.
publishAsTemplate(name)PagePublish this page as a copyable template.
search(query)Page[]Gets an array of descendant pages that match a search query, up to a limit of 200 pages.
search(query, options)Page[]Gets an array of descendant pages that match a search query, with optional advanced arguments.
setHtmlContent(html)PageSet the HTML content of the page.
setIsDraft(draft)PageSets whether the page is in draft mode.
setName(name)PageSet this page's name.
setParent(parent)PageSet the parent of this page.
setTitle(title)PageSet the page's title.

Detailed documentation

addColumn(name)

Add a new column to the list. Only valid for list pages.

var site = SitesApp.getSite("example.com", "mysite");

var page = site.getChildByName("listpage");
// Only valid on List pages. Check for the type like so:
//     if(page.getPageType() == SitesApp.PageType.LIST_PAGE))
var columns = page.addColumn("new-column");

Parameters

NameTypeDescription
nameStringthe new column's name

Return

Column — the newly created column

Throws

Error — for pages that aren't list pages

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

addHostedAttachment(blob)

Add an attachment to the page.

var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];

// Create a new blob and attach it. Many useful functions also return
// blobs file uploads, URLFetch
var blob = Utilities.newBlob("Here is some data", "text/plain", "data.txt");

// Note that the filename must be unique or this call will fail
page.addHostedAttachment(blob);

Parameters

NameTypeDescription
blobBlobSourcethe data for the attachment

Return

Attachment — the newly created attachment

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

addHostedAttachment(blob, description)

Add an attachment to the page. This version of the function allows for a description.

var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];

// Create a new blob and attach it. Many useful: functions also return
// blobs file uploads, URLFetch
var blob = Utilities.newBlob("Here is some data", "text/plain", "data.txt");

// Note that the filename must be unique or this call will fail
page.addHostedAttachment(blob, "Some newly created data");

Parameters

NameTypeDescription
blobBlobSourcethe data for the attachment
descriptionStringa description of the attachment

Return

Attachment — the newly created attachment

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

addListItem(values)

Add a list item to the list. Only valid for list pages.

var site = SitesApp.getSite("example.com", "mysite");

var page = site.getChildByName("listpage");
// Only valid on List pages. Check for the type like so:
//     if(page.getPageType() == SitesApp.PageType.LIST_PAGE))
// Returns only one item
page.addListItem([ "John", "Smith", "123 Main St"]);

Parameters

NameTypeDescription
valuesString[]the values for each column

Return

ListItem — the newly created ListItem

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

addWebAttachment(title, description, url)

Add a web attachment to the page. Only valid for file cabinet pages.

Web attachments are links - they are not actually hosted by Google Sites.

var site = SitesApp.getSite("example.com", "mysite");
// fetch the child - this must be a File Cabinet page
// to programmatically check this, do a comparison:
//    if(page.getPageType() == SitesApp.PageType.FILE_CABINET_PAGE)
var page = site.getChildByName("files");
page.addWebAttachment("Google Robots file",
                      "This is Google's robots.txt file",
                      "http://www.google.com/robots.txt");

Parameters

NameTypeDescription
titleStringthe title of the attachment
descriptionStringa description of the attachment
urlStringthe url of the file being attached

Return

Attachment — the newly created attachment

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

createAnnouncement(title, html)

Create an announcements for this page. Only valid for announcement pages.

var site = SitesApp.getSite("example.com", "mysite");

// This snippet will only work with announcement pages - this is different
// from a page that is an annoucement (individual announcements). To check
// if this method can be called:
//    if(page.getPageType() == SitesApp.PageType.ANNOUNCEMENTS_PAGE))
var page = site.getChildByName("news");
page.createAnnouncement("Breaking news!", "<h1>Apps Script rocks!</h1>");

Parameters

NameTypeDescription
titleStringthe page title
htmlStringthe page content

Return

Page — the newly created Announcements

Throws

Error — for pages that aren't announcement pages

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

createAnnouncement(title, html, asDraft)

Create an announcements for this page. Only valid for announcement pages.

var site = SitesApp.getSite("example.com", "mysite");

// This snippet will only work with announcement pages - this is different
// from a page that is an annoucement (individual announcements). To check
// if this method can be called:
//    if(page.getPageType() == SitesApp.PageType.ANNOUNCEMENTS_PAGE))
var page = site.getChildByName("news");
page.createAnnouncement("Breaking news!",
                        "<h1>Apps Script rocks!</h1>",
                        true);

Parameters

NameTypeDescription
titleStringthe page title
htmlStringthe page content
asDraftBooleanwhether to make the announcement a draft

Return

Page — the newly created Announcements

Throws

Error — for pages that aren't announcement pages

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

createAnnouncementsPage(title, name, html)

Create a new announcements page. Note that a parent site or page cannot have more than 500 child pages.

// This method can be called from both a Site instance
// as well as a Page instance
var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];

site.createAnnouncementsPage("New Announcement",
                             "new-announcement",
                             "<h1>Your announcement goes here</h1>");

page.createAnnouncementsPage("New Announcement",
                             "new-announcement-child",
                             "<h1>Your announcement goes here</h1>");

Parameters

NameTypeDescription
titleStringthe page title
nameStringthe page name
htmlStringthe page content

Return

Page — the newly created Page

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

createFileCabinetPage(title, name, html)

Create a new file-cabinet page. Note that a parent site or page cannot have more than 500 child pages.

// This method can be called from either a site or a page.
var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];

site.createFileCabinetPage("New File Cabinet",
                           "new-file-cabinet",
                           "<h1>Your HTML here</h1>");

page.createFileCabinetPage("New File Cabinet",
                             "new-file-cabinet-child",
                             "<h1>Your HTML here</h1>");

Parameters

NameTypeDescription
titleStringthe page title
nameStringthe page name
htmlStringthe page content

Return

Page — The newly created Page

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

createListPage(title, name, html, columnNames)

Create a new list page. Note that a parent site or page cannot have more than 500 child pages.

// This method can be called from either a site or a page.
var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];

site.createListPage("New List Page",
                    "new-list-page",
                    "<h1>Your List Page HTML here</h1>",
                    [ "col1", "col2" ]);

page.createListPage("New List Page",
                    "new-list-page-child",
                    "<h1>Your List Page HTML here</h1>",
                    [ "col1", "col2" ]);

Parameters

NameTypeDescription
titleStringthe page title
nameStringthe page name
htmlStringthe page content
columnNamesString[]the column names used for the list

Return

Page — The newly created Page

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

createPageFromTemplate(title, name, template)

Create a new page from a template. Note that a parent site or page cannot have more than 500 child pages.

// This method can be called from either a site or a page.
var site = SitesApp.getSite("example.com", "mysite");
var template = site.getTemplates()[0];

// If an invalid template is passed, this will throw an "Invalid Argument" error.
site.createPageFromTemplate("ClonedPage", "cloned-page", template);

Parameters

NameTypeDescription
titleStringthe page title
nameStringthe page name
templatePagethe template page

Return

Page — the newly created Page

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

createWebPage(title, name, html)

Create a new web page. Note that a parent site or page cannot have more than 500 child pages.

// This method can be called from either a site or a page.
var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];

site.createAnnouncementsPage("New Announcement",
                             "new-announcement",
                             "<h1>Your announcement goes here</h1>");

page.createAnnouncementsPage("New Announcement",
                             "new-announcement-child",
                             "<h1>Your announcement goes here</h1>");

Parameters

NameTypeDescription
titleStringthe page title
nameStringthe page name
htmlStringthe page content

Return

Page — The newly created Page

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

deletePage()

Deletes this page.

var site = SitesApp.getSite("example.com", "mysite");

// Delete ALL the pages!
var pages = site.getAllDescendants();
for(var i in pages) {
  pages[i].deletePage();
}

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getAllDescendants()

Gets an array of descendant pages (direct and indirect), up to a limit of 200 pages.

var site = SitesApp.getSite("example.com", "mysite");
var pages = site.getAllDescendants();

Return

Page[] — an array of direct and indirect child pages

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getAllDescendants(options)

Gets an array of descendant pages, with optional advanced arguments.

var site = SitesApp.getSite("example.com", "mysite");
var descendants = site.getAllDescendants({
  type: SitesApp.PageType.WEB_PAGE,
  start: 0,
  max: 25,
  includeDrafts: false,
  includeDeleted: true,
  search: "target"
});

for(var i in descendants) {
  Logger.log(descendants[i].getName());
}

Parameters

NameTypeDescription
optionsObjectJavaScript object fields defined in the Advanced Arguments section below

Advanced parameters

NameTypeDescription
typePageType[]only get pages of this type
startIntegerstart the results here
maxIntegerthe max number of results (default 200)
includeDraftsBooleanwhether to include draft pages (default false)
includeDeletedBooleanwhether to include deleted pages (default false)
searchStringonly return pages matching this query

Return

Page[] — an array of direct and indirect child pages of the given type

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getAnnouncements()

Get the announcements for this page. Only valid for announcement pages.

var site = SitesApp.getSite("example.com", "mysite");

// This snippet will only work with announcement pages - this is different
// from a page that is an annoucement (individual announcements). To check
// if this method can be called:
//    if(page.getPageType() == SitesApp.PageType.ANNOUNCEMENTS_PAGE))
var page = site.getChildByName("news");
var announcements = page.getAnnouncements();

for(var i in announcements) {
  Logger.log(announcements[i].getHtmlContent());
}

Return

Page[] — an array of Announcements

Throws

Error — for pages that aren't announcement pages

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getAnnouncements(optOptions)

Get the announcements for this page. Only valid for announcement pages.

var site = SitesApp.getSite("example.com", "mysite");

// This snippet will only work with announcement pages - this is different
// from a page that is an annoucement (individual announcements). To check
// if this method can be called:
//    if(page.getPageType() == SitesApp.PageType.ANNOUNCEMENTS_PAGE))
var page = site.getChildByName("news");
var announcements = page.getAnnouncements({ start: 0,
                                            max: 20,
                                            includeDrafts: false,
                                            includeDeleted: false,
                                            search: "Breaking" });

for(var i in announcements) {
  Logger.log(announcements[i].getHtmlContent());
}

Parameters

NameTypeDescription
optOptionsObjectA JavaScript object containing advanced parameters

Advanced parameters

NameTypeDescription
startIntegerthe start index for the results
maxIntegerthe max number of results to return, which defaults to and may not be more than 200
includeDraftsBooleanwhether to include draft pages (default false)
includeDeletedBooleanwhether to include deleted pages (default false)
searchStringonly return pages matching this query

Return

Page[] — an array of Announcements

Throws

Error — for pages that aren't announcement pages

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getAttachments()

Get the attachments for this page.

var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];

var attachments = page.getAttachments();
for(var i in attachments) {
  Logger.log(attachments[i].getTitle());
}

Return

Attachment[] — an array of Attachments

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getAttachments(optOptions)

Get the attachments for this page.

var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];

// This returns only one attachment
var attachments = page.getAttachments({ start: 0, max: 1});
for(var i in attachments) {
  Logger.log(attachments[i].getTitle());
}

Parameters

NameTypeDescription
optOptionsObjecta JavaScript object containing optional parameters

Advanced parameters

NameTypeDescription
startIntegerthe first index to start returning attachments
maxIntegerthe max number of results to return, which defaults to and may not be more than 200

Return

Attachment[] — an array of Attachments

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getAuthors()

Get the emails of the authors of the page

var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];
var authors = page.getAuthors();

for(var i in authors) {
  Logger.log(authors[i]);
}

Return

String[] — an array of author email addresses

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getChildByName(name)

Gets a particular child page.

var site = SitesApp.getSite("example.com", "mysite");
var pages = site.getChildByName("childPage");

Parameters

NameTypeDescription
nameStringthe child page name

Return

Page — the child page

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getChildren()

Gets an array of child pages, up to a limit of 200 pages.

var site = SitesApp.getSite("example.com", "mysite");
var pages = site.getChildren();

Return

Page[] — an array of direct child pages

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getChildren(options)

Gets an array of child pages, with optional advanced arguments.

var site = SitesApp.getSite("example.com", "mysite");
var childPages = site.getChildren({
  type: SitesApp.PageType.WEB_PAGE,
  start: 0,
  max: 25,
  includeDrafts: false,
  includeDeleted: true,
  search: "target"
});

for(var i in childPages) {
  Logger.log(childPages[i].getName());
}

Parameters

NameTypeDescription
optionsObjectJavaScript object fields defined in the Advanced Arguments section below

Advanced parameters

NameTypeDescription
typePageType[]only get pages of this type
startIntegerstart the results here
maxIntegerthe max number of results (default 200)
includeDraftsBooleanwhether to include draft pages (default false)
includeDeletedBooleanwhether to include deleted pages (default false)
searchStringonly return pages matching this query

Return

Page[] — an array of direct child pages of the given type

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getColumns()

Get the columns for the list. Only valid for list pages.

var site = SitesApp.getSite("example.com", "mysite");

var page = site.getChildByName("listpage");
// Only valid on List pages. Check for the type like so:
//     if(page.getPageType() == SitesApp.PageType.LIST_PAGE))
var columns = page.getColumns();

for(var i in columns) {
  Logger.log(columns[i].getName());
}

Return

Column[] — an array of Column instances

Throws

Error — for pages that aren't list pages

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getDatePublished()

Return the date this page was first published.

var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];
Logger.log(page.getName() + " was published " + page.getDatePublished());

Return

Date — the date of original publication

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getHtmlContent()

Get the HTML content of the page.

var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];
Logger.log(page.getHtmlContent());

Return

String — the html content

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getIsDraft()

Returns whether the page is in draft mode. Only valid for announcements.

var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];

Logger.log("Is this Announcement Page a draft?", page.getIsDraft());

Return

Boolean — whether the page is in draft mode

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getLastEdited()

Return the last edit date, which includes only content edits.

var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];
Logger.log(page.getName() + " was last updated " + page.getLastEdited());

Return

Date — the date the page was last updated, including only content edits

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getLastUpdated()

Return the last updated date, which includes non-content changes like moving.

var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];
Logger.log(page.getName() + " was last updated " + page.getLastUpdated());

Return

Date — the date the page was last updated with non-content changes

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getListItems()

Get the list items for the list. Only valid for list pages.

var site = SitesApp.getSite("example.com", "mysite");

var page = site.getChildByName("listpage");
// Only valid on List pages. Check for the type like so:
//     if(page.getPageType() == SitesApp.PageType.LIST_PAGE))
var items = page.getListItems();

for(var i in items) {
  Logger.log(items[i].getValueByName("Status"));
}

Return

ListItem[] — an array of ListItem instances

Throws

Error — for pages that aren't list pages

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getListItems(optOptions)

Get the list items for the list. Only valid for list pages.

var site = SitesApp.getSite("example.com", "mysite");

var page = site.getChildByName("listpage");
// Only valid on List pages. Check for the type like so:
//     if(page.getPageType() == SitesApp.PageType.LIST_PAGE))
// Returns only one item
var items = page.getListItems({ start:0, max: 1 });

for(var i in items) {
  Logger.log(items[i].getValueByName("Status"));
}

Parameters

NameTypeDescription
optOptionsObjectA JavaScript object of optional parameters

Advanced parameters

NameTypeDescription
startIntegerthe first index to start iterating from
maxIntegerthe max number of results to return, which defaults to and may not be more than 200

Return

ListItem[] — an array of ListItem instances

Throws

Error — for pages that aren't list pages

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getName()

Return the page's name.

var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];
Logger.log(page.getName());

Return

String — the name of this page

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getPageType()

Return the type of this page as a SitesApp.PageType enum.

var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];
var pageType = page.getPageType();
if(pageType == SitesApp.PageType.WEB_PAGE) {
   Logger.log(page.getName() + " is a Web Page");
}

Return

PageType — a PageType enum telling whether this is a Web, List, Announcement or File Cabinet Page

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getParent()

Return the parent of this page.

var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];
Logger.log(page.getName() + " parent: " + page.getParent().getName());

Return

Page — the parent page of this page

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getTextContent()

Returns the plain-text page content.

var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];
Logger.log(page.getName() + " content: " + page.getTextContent());

Return

String — the plain-text content of the page

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getTitle()

Return the page's title.

var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];
Logger.log(page.getTitle());

Return

String — the title of this page

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

getUrl()

Get the url of the page.

var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];
Logger.log(page.getUrl());

Return

String — the url of the page

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

isDeleted()

Returns whether a page has been deleted.

Return

Boolean — whether the page has been deleted

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

isTemplate()

Returns whether this page is a copyable template.

var site = SitesApp.getSite("example.com", "mysite");
var firstTemplate = site.getTemplates()[0];
if(firstTemplate.isTemplate()) {
  Logger.log("This will always return true");
}

Return

Boolean — whether this page is a template

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

publishAsTemplate(name)

Publish this page as a copyable template.

var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];

// Turn this page into a publishable template
page.publishedAsTemplate("template-name");

Parameters

NameTypeDescription
nameStringThe name of the new template

Return

Page — the newly published template

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

search(query)

Gets an array of descendant pages that match a search query, up to a limit of 200 pages.

var site = SitesApp.getSite("example.com", "mysite");
var matches = site.search("targetText");

for(var i in matches) {
  Logger.log(matches[i].getName());
}

Parameters

NameTypeDescription
queryStringthe full text search query to match

Return

Page[] — an array of direct and indirect child pages of the given type

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

search(query, options)

Gets an array of descendant pages that match a search query, with optional advanced arguments.

var site = SitesApp.getSite("example.com", "mysite");
var childPages = site.getChildren({
  type: SitesApp.PageType.WEB_PAGE,
  start: 0,
  max: 25,
  includeDrafts: false,
  includeDeleted: true,
  search: "target"
});

for(var i in childPages) {
  Logger.log(childPages[i].getName());
}

Parameters

NameTypeDescription
queryStringthe full text search query to match
optionsObjectJavaScript object fields defined in the Advanced Arguments section below

Advanced parameters

NameTypeDescription
typePageType[]only get pages of this type
startIntegerstart the results here
maxIntegerthe max number of results (default 200)
includeDraftsBooleanwhether to include draft pages (default false)
includeDeletedBooleanwhether to include deleted pages (default false)

Return

Page[] — an array of direct and indirect child pages of the given type

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

setHtmlContent(html)

Set the HTML content of the page.

var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];
page.setHtmlContent("<h1>New Page Content</h1>");

Parameters

NameTypeDescription
htmlStringthe new content

Return

Page — this Page for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

setIsDraft(draft)

Sets whether the page is in draft mode. Only valid for announcements.

var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];

// Take the page out of draft mode
page.setIsDraft(false);

Parameters

NameTypeDescription
draftBooleanthe new status

Return

Page — this Page for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

setName(name)

Set this page's name.

var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];
page.setName("new-name");

Parameters

NameTypeDescription
nameStringthe new name

Return

Page — this Page for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

setParent(parent)

Set the parent of this page.

var site = SitesApp.getSite("example.com", "mysite");
var child = site.getChildByName("childToBeMoved");
var parent = site.getChildByName("newParent");
child.setParent(parent);

Parameters

NameTypeDescription
parentPagethe new parent

Return

Page — this Page for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

setTitle(title)

Set the page's title.

var site = SitesApp.getSite("example.com", "mysite");
var page = site.getChildren()[0];
page.setTitle("New Title");

Parameters

NameTypeDescription
titleStringthe new title

Return

Page — this Page for chaining

Authorization

Scripts that use this method require authorization with one or more of the following scopes:

  • https://sites.google.com/feeds

Deprecated methods