How to create a modern page using cusotm templage in JSOM

Contributor

Hi,

 

Can any one advise how to create a modern page uisng custom page template in JSOM

 

Any kind of help is appricieated.

 

Thnaks,

 

2 Replies

@mytech1982 

 

There is not default method provided in JSOM to create page from template but you can add new client side page and copy everything from template page.

 

If you able to use PnP Js then you can use Copy method which is being used for copying page.

 

Copy Page 

 


Hope it will helpful to you and if so then Please mark my response as Best Response & Like to help others in this community

 

 

@mytech1982 Check and try if there are any JSOM equivalent functions available for below CSOM code (code taken from this thread:( 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using ClientSidePage = OfficeDevPnP.Core.Pages.ClientSidePage;
using System.Security;

namespace CreatePageFromTemplate
{
 class Program
 {
	 static void Main(string[] args)
	 {
		 string userName = "email address removed for privacy reasons";
		 string password = "**************";
		 using (ClientContext clientContext = new ClientContext("https://Tenant.sharepoint.com/sites/SiteName"))
		 {
			 SecureString securePassword = new SecureString();
			 foreach (char c in password.ToCharArray())
			 {
				 securePassword.AppendChar(c);
			 }

			 clientContext.AuthenticationMode = ClientAuthenticationMode.Default;
			 clientContext.Credentials = new SharePointOnlineCredentials(userName, securePassword);

			 // Load the template page
			 ClientSidePage page = clientContext.Web.LoadClientSidePage("Templates/MyTemplate.aspx");

			 // Create and Save the modern page based on the template
			 page.Save("IT_Australia1.aspx");
		 }

	 }
 }
}

 


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.