Templates operations

Overview

Page templates are similar to Sitefinity CMS content types in terms of API. You can create, retrieve, update, and delete templates in the same way you do this with news, lists, and dynamic types.

Get a collection of templates

To get a collection of templates, execute a POST request to one of the the following:

{baseurl}/api/default/templates
This request gets all templates from all sites and all templates not used on any site.

{baseurl}/api/default/templates/filters(name=@sf_filter)?@sf_filter='{filter_param}
Where {filter_param} is one of the following:

  • ThisSite – return templates only for the current site
  • AllSites – returns all templates in the system (equivalent to no filter applied)
  • NoSite – returns templates that are not shared with any site

{baseurl}/api/default/templates/filters(name=@sf_filter)?@sf_filter='ThisSite'&sf_site={site_id}
Where {site_id} is the ID of the site where you want to get all templates from.

Sample request (all sites)

GET http://mysite.com/api/default/templates

Sample request (current site)

GET http://mysite.com/api/default/templates/filters(name=@sf_filter)?@sf_filter='ThisSite'

To get the templates from the current site only, add a filter to the request.

Sample request (filter by site)

GET http://mysite.com/api/default/templates/filters(name=@sf_filter)?@sf_filter='ThisSite'&sf_site=23791361-ae8a-4d86-9873-01d2b5654ea0

To get the templates for a specific site, you must add to the request the sf_site query parameter.

Sample response

Get a collection of templates grouped by framework

The format of the response to this request is different, because it groups all templates that are requested by the framework type that they are based on – for example, Bootstrap, Minimal, Custom, Hybrid, .NET Core.

To get grouped templates, execute a GET request to the following endpoint:

{baseurl}/api/default/templates/Default.GetPageTemplates(selectedPages=[])

NOTE: Use this approach to get all .NET Core templates, In this case, you should point the {baseurl} to the URL of the Sitefinity .NET Core Renderer application.

Sample request

GET http://mysite.com/api/default/templates/Default.GetPageTemplates(selectedPages=[])

Sample response

Get a collection of template thumbnails

When you create a template, using a POST request, in the request body, you must specify whether you want to use a specific thumbnail to represent the template. You do this, by passing the ID of the thumbnail that you want to use for the new template. If you use an empty GUID, the system applies the default thumbnail.

If you want to use other than the default template thumbnail, you must first get all available thumbnails, by executing a GET request to the following endpoint:

{baseurl}/api/default/images?sf_provider=SystemLibrariesProvider

Sample request

GET http://mysite.com/api/default/images?sf_provider=SystemLibrariesProvider

Create a template

To create an MVC, Hybrid, or .NET Core template, execute a POST request to the following endpoint:

{baseurl}/api/default/templates

When you create a template, you assign it a thumbnail, by passing its ID in the request body. The Thumbnail property is the ID of the image that you want to use as a thumbnail to represent the template.

  • If you want to use a custom thumbnail, you must first get all available thumbnails, using the procedure above.
  • If you want to use the default thumbnail, set the Thumbnail property to an empty GUID - 00000000-0000-0000-0000-000000000000

Sample request

POST http://mysite.com/api/default/templates

The TemplateId property is the ID of the template, which you want to base the new template on.

  • If you want your template to be based on a new MVC layout, set the ThumbnailId property to an empty GUID - 00000000-0000-0000-0000-000000000000
  • If you want to create a new Hybrid template, do not include the ThumbnailId property in the request body.

NOTE: When you create a new template and you base it on another template, the new template inherits the framework – MVC or Hybrid, from the base template.

You create a .NET Core template by basing it on another .NET Core template. You can also base your new template on the default .NET Core template.

The TemplateName property points to the template that you want to use as a base, which must be a .NET Core one.

Sample response

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?

Next article

Sitemap operations