Thursday, May 2, 2019

How to: Creating modern page templates, and retrofitting old pages as templates

Microsoft is in the process of rolling out modern page templates, which is something we've been waiting for for a good long while now. And finally the time has come :)

I've seen it in most tenants, but not all - so be patient as it's trickling in.

If you haven't tested this yet I'll do a quick walk-thru.

To create a template you perform the following steps: Create a new modern page, add all there is to it, hit publish, and you get the option to save the page as a template as seen in the image below.

Note: The option to save as a template only show the first time you publish, but the option is available if you click the Promote button on a page as well.

Once you have created a template it will show up when you click New page from the menu on any existing modern page (it does not show while in the Site Pages library or the cog wheel Add a page at the time of writing).

What if you have existing pages you want to use as templates? One option is to start a new page with Copy of this page, and follow the steps above. Then delete the original page you used as a template as well as your new copy.

But as we're all savvy modern users we know it's simpler. If  you look at how the template feature is actually implemented, you will quickly get the drift. Once you create your first template a folder named Templates is created in the Site Pages library and any page in this folder will show as a template.

Note: If the file you move has been published as a major version at one time or another, the template will also show in search. Same goes if you turn off minor versioning on the Site Pages library. So you might want to create a template from that file instead, and then delete the files still....

This means you can retro-fit existing templates in a site performing the following steps:
  • Create a dummy template in order to have the Template folder created and enabled for templating.
  • Select the page you want as a template, and drag/move it to the Templates folder, as there is no move command on the Site Pages library.
  • Navigate to the Templates folder and open the page and you see it's now been templaty'fied
When you now want to create a new page, the template will show up as easy as corral balls!

For the techies out there

A big thank you to Erwin Van Hunen for helping on this one.

If you manually want to set up the templating feature, say in a provisioning scenario, do the following:

  • Create a folder in Site Pages (name it whatever you want) and record the unique guid of the folder

    $f = Get-PnPFolder  SitePages/MyTemplates -Includes UniqueId
  • In the property bag of the Site Pages library, set vti_TemplatesFolderGuid to that guid

    Set-PnPPropertyBagValue -Key "vti_TemplatesFolderGuid" -Value $f.UniqueId -Folder "SitePages"