Adding layout controls to pages and page templates

Overview

You can add layout controls to Pages and Page Templates. To create a LayoutControl to a Page or PageTemplate, you must:

  • Specify its type – If you will be adding the control to a Page, use a PageControl, but if it will be added on a Template, use a TemplateControl.
  • Specify its Caption – The text that is the label of your LayoutControl when it is dropped on a page or template.
  • Specify its Layout – The path to the LayoutControl’s template file (.ascx). For more information about the .ascx, see Layout widgets: Create custom layout widgets.
  • Specify its Placeholder – The name of the Placeholder on the Page or Template where your LayoutControl will be placed. By default, you can use “Body” which means your layout will be placed among all other controls in the main Body placeholder of the page/template. Alternatively you can query a specific placeholder on a page(or its template), for example:

Add a LayoutControl to a page

You add the Layout Control to the intended object’s Controls collection. The following example shows how to create a LayoutControl, and then add it to a Page:

Add a LayoutControl to a Page Template

You simply add theLayoutControl to the intended object’s Controls collection. The following example shows how to create a LayoutControl, and then add it to a Page Template:

Query LayoutControls

To query the LayoutControls, you access the Controls collection on the Page or Template to work on those where the ObjectType is LayoutControl.

Example of a query of the LayoutControls on a Page by the Caption property: Example of a query of the LayoutControls on a page's Page Template:

Work with LayoutControl’s placeholders

When you want to put a widget inside a LayoutControl programmatically, you work with the Placeholders collection of the LayoutControl. The placeholders are the containers that form the docking zones in Sitefinity that allow you to “dock” a widget on them. For example, a LayoutControl whose template defines only a single 100% layout has a single Placeholder object in its Placeholders collection. A LayoutControl with 3 columns has three Placeholders. First, you must locate the Placeholder you want. Since the Placeholders collection is a string [] you use index to get the desired Placeholder. For example:

Then you specify the widget’s placeholder. When you create a new widget that will be added to a Sitefinity page through code, you can supply the placeholder on the page where it will be added. To do this, use the the PageManager.CreateControl<T>()method. The following example shows the creation of a basic ContentBlock and setting its placeholder before adding it to the page:

Code sample

The following sample demonstrates:

  • Creating a PageTemplate
  • Adding a LayoutControl to it
  • Creating a Page based on the Template
  • Adding a control in the template’s placeholder on the page

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?