Making Your Sitefinity Widget Templates Editable through the UI - Part 2

Making Your Sitefinity Widget Templates Editable through the UI - Part 2

November 14, 2013 0 Comments

The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.

This blog post is an extension to the blog post from Slavo Ingilizov for making widget templates editable trough the UI.

This blog post will address how to make the custom widget template persist in the UI after it has been edited (not removed after a single edit to the template) and how to create a custom resource class which will create new area name for the widget so that it can be placed in different areas from the preexisting areas of the built-in widgets.

1. Registering the widget template and making it persist in the UI.

To make the widget template persist in the class for the widget, add a new attribute ControlTemplateInfo:

[ControlTemplateInfo("CustomControlResources", "FriendlyName", "WidgetArea")]
    public class NewWidget : SimpleView
    {
//rest of the widget implementation is below

ControlTemplateInfo makes the widget template for this widget registered to a specific Area, and it accepts three parameters:

"CustomControlResources" - This is the resource name, I will describe how to create custom resource below.

"FriendlyName" - this is the name of the section toward which this template belongs, in case a single widget has multiple templates registered for it.

"WidgetArea" - this is the Area in which the widget is registered (see screenshot below).






























2. Add a custom resource class creating the resource entries used in the above registration.

2.1 Create a class that inherits Sitefinity.Localization.Resource. The class used for the above resources is provided below:

using Telerik.Sitefinity.Localization;
using Telerik.Sitefinity.Localization.Data;
 
namespace SitefinityWebApp
{
    [ObjectInfo("CustomControlResources", ResourceClassId = "CustomControlResources")]
    public class CustomControlResources : Resource
    {
        public CustomControlResources()
        {
        }
 
        public CustomControlResources(ResourceDataProvider dataProvider)
            : base(dataProvider)
        {
        }
 
        [ResourceEntry("WidgetArea",
                       Value = "WidgetArea",
                       Description = "The title of this class.",
                       LastModified = "2009/05/13")]
        public string BlogResourcesTitle
        {
            get
            {
                return this["WidgetArea"];
            }
        }
 
        [ResourceEntry("FriendlyName",
            Value = "Friendtly name of the control",
            Description = "description",
            LastModified = "2010/11/11")]
        public string BlogsMasterViewFriendlyName
        {
            get
            {
                return this["FriendlyName"];
            }
        }
    }
}

2.2. To register and use the custom resource class in Global.asax, register the class by subscribing to Bootsrapper.Initialized in Application_Start event:

protected void Application_Start(object sender, EventArgs e)
       {
           Bootstrapper.Initialized += new EventHandler<Telerik.Sitefinity.Data.ExecutedEventArgs>(this.AfterInit);
       }
 
       private void AfterInit(object sender, ExecutedEventArgs args)
       {
           Res.RegisterResource<CustomControlResources>();
       }
 
The registered custom resource class can further be extended with additional resource entries from the Administration-> Interface Labels and Messages module.

3. Registering the widget template for the control using the resource class entries

The widget template registration can be altered to include the resource classes for which the widget has been registered.

var initializer = SiteInitializer.GetInitializer();
 
           initializer.RegisterControlTemplate(
                   "SitefinityWebApp.TestWidget.NewWidget.ascx",
                   typeof(NewWidget).FullName,
                   "NewWidget",
                   null,
                   "CustomControlResources",
                   "ASP_NET_TEMPLATE",
                   typeof(NewWidget).Assembly.FullName,
                   "FriendlyName"
                   );
           initializer.SaveChanges();

Stanislav Velikov

Stanislav Velikov is a Tech Support Engineer at Telerik. He joined the Sitefinity Support team in April 2011.

Comments
Comments are disabled in preview mode.
Topics
 
 
Latest Stories in
Your Inbox
Subscribe
More From Progress
d12fcc0bdb669b804e7f71198c9619a7
5 Questions Automakers Should Ask to Improve Asset Uptime
Download Whitepaper
 
SF_MQ_WCM
2018 Gartner Magic Quadrant Web Content Management (WCM)
Download Whitepaper
 
What-Serverless-Means-For-Enterprice-Apps-Kinvey
What Serverless Means for Enterprise Apps
Watch Webinar