SOLVED

Can we add the same templates on multiple document libraries

Steel Contributor

I have created a PDF template named Shipping, inside a document library inside our SharePoint online, as follow:-

 

image.png

 

 

now i need to share this template with 20 document libraries, is there an easy way to do so?

 

Thanks

6 Replies

Hi @john john,

There are a few ways to add the same template to multiple document libraries in SharePoint Online, but I think that the best solution is using the Copy Template feature. It's the simplest way to do it.

 

  1. Go to the document library that contains the template you want to copy.
  2. Click the Template tab.
  3. Select the template you want to copy and click Copy Template.
  4. In the Copy Template dialog box, select the Save to SharePoint option and click Next.
  5. Select the document library where you want to copy the template and click Copy.

You can also use PowerShell for that. 

You can try to use this example (template):

 

$templateURL = "https://[your-site-url]/[document-library-URL]/[template-name].pdf"
$documentLibraries = @[
    "https://[your-site-url]/[document-library-URL-1]",
    "https://[your-site-url]/[document-library-URL-2]",
    "https://[your-site-url]/[document-library-URL-3]"
]

foreach ($documentLibrary in $documentLibraries) {
    $outputFile = "$documentLibrary/[template-name].pdf"
    Copy-Item -Path $templateURL -Destination $outputFile -Force
}

 

 

To use this script, you will need to enter the values from youe environment.

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.


Kindest regards,


Leon Pavesic

best response confirmed by john john (Steel Contributor)
Solution

Hi @john john ,

you can automate that if you use PnP Powershell.

First modify the "New" menu of one document library like you want them all to look. Then execute these Powershell commands

# Get the template
Connect-PnPOnline https://<tenant>.sharepoint.com/sites/<site> -UseWebLogin
$listname="Name of the base document library"
$view = Get-PnpView -List $listname | Where-Object {$_.DefaultView -eq $true}
$template=$view.NewDocumentTemplates


This will load the configuration of the "New" menu inside of the variable "$template". Keep the PowerShell window open and enter these lines

# If the library is on a different site than the other library
#Connect-PnPOnline https://<tenant>.sharepoint.com/sites/<site> -UseWebLogin

$listname="Name of the documentlibrary you want to apply the template to"
$view = Get-PnpView -List $listname | Where-Object {$_.DefaultView -eq $true}
$view.NewDocumentTemplates = $template
$view.Update()
Invoke-PnPQuery	

 That will apply the same "New" Menu to that other document library. It will not upload the document templates a second time but will configure both libraries to use the same template file.

Best Regards,
Sven

@john john 

you may automate that by using PnP Powershell commands as discribed below.

Firstly you need to modify the '"New"' menu of one of the document library like you want them all to be look a like. Then execute the below Powershell commands as mentioned : -

# Get the template
Connect-PnPOnline https://<tenant>.sharepoint.com/sites/<site> -UseWebLogin
$listname="Name of the base document library"
$view = Get-PnpView -List $listname | Where-Object {$_.DefaultView -eq $true}
$template=$view.NewDocumentTemplates

That will load the configuration of "New" menu inside of variable "$template".

Remain the PowerShell window open and enter the below lines : -

# If the library is on a different site than the other library
#Connect-PnPOnline https://<tenant>.sharepoint.com/sites/<site> -UseWebLogin

$listname="Name of the documentlibrary you want to apply the template to"
$view = Get-PnpView -List $listname | Where-Object {$_.DefaultView -eq $true}
$view.NewDocumentTemplates = $template
$view.Update()
Invoke-PnPQuery	

This will apply the same "New" Menu to the anyother document library and you able to use the same template with mutiple document libraries.


Kind Regards,
Adnan

@SvenSieverding  thanks a lot for your reply, i tested this on my test site and it worked well,, but before applying this to PROD , will this cause any drawbacks to the document libraries? since they will reference others libraries templates? do you have any documentations about those commands as i could not find any

@LeonPavesicThanks for the reply. i could not find the Templates section inside the document libraries settings, can you advice from where i can find it?

 

also your power shell script will create a copy of the templates, is there a way to have all templates referencing one main template, so when changing the main template all the underlying templates which reference the main template will get the change?

Hi @john john,

The Templates section in the document library settings is only available for classic SharePoint sites. In modern SharePoint sites, the templates are managed using the New Document menu.

To access the New Document menu, go to the document library where you want to add the template. Then, click the New button.

In the New Document menu, you will see a list of all of the templates that are available in the document library. To add a new template, click the + Add template button.

To create a template from an existing document, click the Create from existing button. Then, select the document that you want to use as the template.

To create a template from scratch, click the Create new button. Then, select the type of template that you want to create.

Once you have created the template, you can add it to the New Document menu by clicking the Add to New button.

To have all templates referencing one main template, you can use the following steps:

  1. Create a central library where you will store the main template.
  2. Create a PowerShell script to copy the main template to each document library.
  3. Use PnP PowerShell to update the New Document Templates menu in each document library to reference the main template.

Here is a sample PowerShell script that you can use to copy the main template to each document library:

 

$templateURL = "https://[your-site-url]/[central-library-URL]/[template-name].pdf"
$documentLibraries = @[
    "https://[your-site-url]/[document-library-URL-1]",
    "https://[your-site-url]/[document-library-URL-2]",
    "https://[your-site-url]/[document-library-URL-3]"
]

foreach ($documentLibrary in $documentLibraries) {
    $outputFile = "$documentLibrary/[template-name].pdf"
    Copy-Item -Path $templateURL -Destination $outputFile -Force
}

 

 

Here is a sample PnP PowerShell command that you can use to update the New Document Templates menu in each document library:

 

Connect-PnPOnline https://<tenant>.sharepoint.com/sites/<site> -UseWebLogin
$templateURL = "https://[your-site-url]/[central-library-URL]/[template-name].pdf"
$documentLibraries = @[
    "https://[your-site-url]/[document-library-URL-1]",
    "https://[your-site-url]/[document-library-URL-2]",
    "https://[your-site-url]/[document-library-URL-3]"
]

foreach ($documentLibrary in $documentLibraries) {
    $view = Get-PnpView -List $documentLibrary | Where-Object {$_.DefaultView -eq $true}
    $template = New-PnPListItemTemplate -Url $templateURL
    $view.NewDocumentTemplates = $template
    $view.Update()
    Invoke-PnPQuery
}

 

 

Once you have run these scripts, all of the document libraries will reference the main template. When you make a change to the main template, the change will be reflected in all of the document libraries.


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.


Kindest regards,


Leon Pavesic

1 best response

Accepted Solutions
best response confirmed by john john (Steel Contributor)
Solution

Hi @john john ,

you can automate that if you use PnP Powershell.

First modify the "New" menu of one document library like you want them all to look. Then execute these Powershell commands

# Get the template
Connect-PnPOnline https://<tenant>.sharepoint.com/sites/<site> -UseWebLogin
$listname="Name of the base document library"
$view = Get-PnpView -List $listname | Where-Object {$_.DefaultView -eq $true}
$template=$view.NewDocumentTemplates


This will load the configuration of the "New" menu inside of the variable "$template". Keep the PowerShell window open and enter these lines

# If the library is on a different site than the other library
#Connect-PnPOnline https://<tenant>.sharepoint.com/sites/<site> -UseWebLogin

$listname="Name of the documentlibrary you want to apply the template to"
$view = Get-PnpView -List $listname | Where-Object {$_.DefaultView -eq $true}
$view.NewDocumentTemplates = $template
$view.Update()
Invoke-PnPQuery	

 That will apply the same "New" Menu to that other document library. It will not upload the document templates a second time but will configure both libraries to use the same template file.

Best Regards,
Sven

View solution in original post