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.
In our last post, we looked at how to use the Sitefinity Backend Page Editor to easily create Page Based Modules. This time we'll take things a step further by wrapping this process into a Sitefinity module, complete with support for installing and uninstalling with the click of a button!
In the video below, I walk you through converting the Page-Based module into a self-contained, installable module, similar to the "Intra-Site" Modules of Sitefinity 3.x. We reuse the same User Controls from the previous video on Page-Based Modules, registering them in both the Admin pages the Installer creates as well as adding them to the toolbox.
Click below to watch the video, then read on for more details.
Watch on Telerik.tv
To define a custom module in Sitefinity 4, you simply need to inherit from ModuleBase. Although there is a more specialized base class we would use for Content-based Modules (ContentModuleBase), in this case, we are not using any Sitefinity components, but rather have developed our own controls that we simply want to open inside of Sitefinity.
Each of the abstract methods needs to be implemented, however once again, since our module is simple, we can return null or simply ignore most of them. The main components of Intra-Site Modules are the LandingPageId property and the Install method.
This is simply used to hard-code a unique identifier for the admin page for your module. This can be any Guid value, but each module of course must have its own unique value.
In addition, you can also add additional page IDs if you want your module to install multiple pages or subpages. This is handled in the Install method.
Here is where everything that is needed to run the module is setup, including creating the pages, registering the admin controls inside that page, and adding the widget to the toolbox.
The completed install routine is available within the downloads section below, which contains module we created in the video, fully commented and ready to add to any existing Sitefinity website.
Once the module is completely defined, there is nothing more that needs to be done other than install it in the Sitefinity Administration, as outlined in the documentation: Registering a Module.
However, by adding a pair of static methods to the class that do this same process in code, we can then create an installer page. This installer page calls these static methods as needed to install or uninstall the module, which takes care of registering (or removing) everything for you.
The methods we created for this module even take care of restarting Sitefinity so that you do not have to open and save your web.config. This allows complete control of the module within Sitefinity.
Implementing the Install and Uninstall methods open up a great extensibility point in Sitefinity, allowing you to reuse a lot of existing controls and easily import them into Sitefinity. Best of all, since they are compiled along with your project, there are minimal issues with compatibility between Sitefinity releases.
There are several ways we can improve this, including moving everything to a separate class library so that you can distribute your module in a truly self-contained manner, perhaps through the Sitefinity Marketplace.
I will also be exploring how you can further enhance intra-site modules by tapping into security, workflow, and other integrated features of Sitefinity. Stay tuned for more.
In the meantime, download the sample project below and give it a try. I also plan to develop a more "real world" example for the next release of the SDK coming in a few weeks. If you have any suggestions for the type of module you'd like to see implemented, please leave your comments below, or as always, visit our Sitefinity Discussion Forum.
Instructions: Extract to the root of your site, so that the path is ~/Modules/HelloWorld. Then launch the page ~/Modules/HelloWorld/Setup.aspx.
View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Subscribe to get all the news, info and tutorials you need to build better business apps and sites
Copyright © 2019 Progress Software Corporation and/or its subsidiaries or affiliates.
All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.