Set predefined values for widget properties

Overview

With the help of widget designers, you can configure a wide range of widget properties that define how the specific widget behaves and looks and what content it displays. Properties range from simple ones, such as configuring which news items to display, to more complex ones, such as CSS class and canonical URL tags. Properties can also be defined on different levels of the widget properties hierarchy, for example, a property may be located in the Advanced properties > Model of a widget designer. For more information, see Widget designers.

Say you have a personal blog and you want to predefine values for the properties of the Blog post widget. You want every such widget dropped on the page to list just 5 blogs and you want all of them to have a short description and sort them by last modified on top. You also want a group of metafields, for example, SEO or keywords pre-filled with a set of terms, so that you do not have to do this for every single Blog post widget you use. You can easily do this by having the respective widget properties pre-filled with values that apply to all Blog post widgets.

By setting predefined values for widget properties, you:

  • Provide consistency in behavior and appearance of a specific widget
  • Increase efficiency by decreasing the number of clicks and configurations needed for each and every widget of the same type
  • Make it easier for users to work with widgets by avoiding the need to look for specific properties throughout the widget designer or having to know precise property values
  • Lower the risk of errors when configuring widgets

Keep in mind that even if you set predefined values for properties, they may also be edited at a later point in time and are not hard-coded. That is, you can still edit all these properties per widget in the widget designer.

You predefine properties of all Sitefinity CMS widgets, as well as of dynamic content widgets and widgets you implemented from scratch.

NOTE: You can set property values for both MVC and Web Forms widgets.

Set the property values

You predefine values for widget properties in Advanced settings.  Each property consists of:

  • Key
    The name of the property, for example, ItemsPerPage
  • Value
    The actual value, for example, 5

Say you want to set predefined values for the dynamic CustomBlogPost widget.

  1. Navigate to the following location:
    Sitefinity backend » Administration » Settings » Advanced » Toolboxes » PageControls » Sections CustomBlogPost section » Tools » CustomBlogPostWidget » Toolbox item parameters
  2. Click Create new to add a property for each widget characteristic you need to configure.
    You need to follow a syntax when entering properties values.

    IMPORTANT: We do not recommend changing the values of the properties already listed in the Toolbox item parameters section.

The following table summarizes the predefined values for widget properties use cases, also taking into account the hierarchy of the properties within the designer. Thus, first level properties are accessible just by opening the widget designer. By contrast, second level is accessible after you go one level deeper in the model properties. Custom level refers to the cases when the property is located more than two levels deep within the designer.

Property hierarchical level Property description New parameter

First level

CssClass property

Key: CssClass
Value: MyCssClass

Second level

Model » property CssClassFromModel

NOTE: The example above is for an MVC widget. The same logic applies for Web Forms widgets, as well.

Key: Model.CssClassFromModel
Value: MyCssClassValueTheModel


Custom level

To add the property path, you use a period “.

Model » Author » Name and Country properties

NOTE: The example above is for an MVC widget. The same logic applies for Web Forms widgets, as well

Key: Model.Person.Name
Value: John

Key: Model.Person.Country
Value: United Kingdom

Predefined values and new widgets

Predefined values for new properties are only applied to new widgets. That is - widgets you drop on pages from this moment on and not for widgets already placed on pages. In addition

In addition, if a user edits a page and meanwhile a widget is configured to have predefined values, even if the user drops this same widget on the page while editing it, the widget will not have predefined values applied. To get the predefined values populated for newly dropped widgets of this type, the user needs to exit page editing mode and then open the page for editing once again.

Set values for SEO and OpenGrpah properties

To set default values related to SEO and OpenGraph properties for your Custom Blog Post widget:

Navigate to Sitefinity backend » Administration » Settings » Advanced » Toolboxes » PageControls » Sections CustomBlogPost section » Tools » CustomBlogPostWidget» Toolbox item parameters

Add new parameter:

Key: MetadataFields.{FieldName}

Value: MyTestValue

Set predefined values in the config file

You can also set predefined values for widget properties in the ToolbocConfig.config file. You need to keep in mind, however, that the toolbox config files are persisted in the database for new projects. The configuration file is stored in the sf_xml_config_items database. Since the predefined values are stored in the database, if you move your project to different environments, the properties and values configurations are not automatically transferred along to the next environment. To do so, you need to perform a manual update to ToolboxesConfig.config file in the database, so that the configuration includes the predefined values.

Was this article helpful?