Sitefinity 12.1 Feature: Predefined Values For MVC Widget Properties

by Nov 5, 2019Sitefinity Developer0 comments

Hey, guys welcome back, Craig from Code Engage. Today we’re going to talk about predefined values for MVC widgets.

In this next series of blog posts, I’m going to talk about all of the new features in Sitefinity 12.1. In today’s post, we’re going to talk about predefined values for widget properties and how to set them up.

Widgets provide functionality for the pages on a Sitefinity website. And they’re highly configurable through a set of properties. To edit these properties just click the edit button for a widget and then click the advanced button.

These widget properties make up the configuration for this widget. But what if you want to apply consistent settings across all of your widgets, how would you do that? Setting these properties can become very cumbersome. This is where predefined values for widget properties come in.

This technique can save you a lot of time. Predefined values for widgets can work for both web form and MVC widgets. You can also set predefined values for built-in widgets, dynamic module widgets, and even custom widgets.

So how do I use predefined values for widgets? Getting the value for a widget property is very simple.

Getting The Property Name

Let’s say for example we want to set the number of pages per page to 10 instead of the normal 20 when listing news releases. You can do this very easily by finding the property that you want to modify, In this example, the property we are looking for is “ItemsPerPage”. To set the default value for this property you will need to use dot notation. In this case, the property value that you want to override would be “Model.ItemsPerPage”.

The naming scheme for a property is simple to understand. Widgets at the root of the advanced properties window will just be the property name. If the property is under the “Model” section we would use the name “Model.”.

Add Property Name To The Toolbox Configuration

Now to set the defined property for the widget just go to the Sitefinity back end select administration, settings, advanced, toolboxes, page controls, sections, content toolbox section, tools, News_MVC, toolbox item parameters. Also, be aware that there are two versions of every widget, an MVC and Web Forms version.

Next, click the create a new button and set the key to “Model.ItemsPerPage”. Set the value to 10. Then click save changes.

Now when you add a new instance of that News MVC widget to a Sitefinity page the widget property, “Items Per Page” will have a new predefined value.

So now you’ve created a predefined value for a widget, And this is great because it will help to provide consistency for all of your widgets that are created going forward.

Thanks again and stay code engaged.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

seven + 12 =

In This Post