Thank you to all who attended today’s webinar. Below are the resources mentioned during the webinar including the video, code snippets and the downloadable project.
Video
Admin Control HTML Markup
This code can be used to make your admin controls fit nicely inside Sitefinity, resembling other built-in modules with a consistent look and feel.
<h1 class="sfBreadCrumb"> <!-- Page Title --> </h1> <div class="sfMain sfClearfix"> <div class="sfMain sfClearfix"> <div class="sfAllToolsWrapper"> <div class="sfAllTools"> <div class="sfActions"> <!-- Toolbox --> </div> </div> </div> <div class="sfWorkArea sfClearfix"> <div class="rgTopOffset"> <!-- Workspace --> </div> </div> </div> </div>
If you want to add a “Create” button that resembles that of other modules, use the following code in the toolbox area.
<ul> <li class="sfMainAction"><span>
<a class="sfLinkBtn sfNew" href="#">
<span class="sfLinkBtnIn">Create Item</span></a>
</span></li> </ul>
CreatePage Helper Method
This method simplifies installation of multiple pages for your backend administration.
/// <summary> /// Creates the page. /// </summary> /// <param name="pageManager">The page manager.</param> /// <param name="pageID">The ID of the page to be created.</param> /// <param name="parentPageID">The ID of the parent page under which to create the new page.</param> /// <param name="UrlName">Name Url used to access the page.</param> /// <param name="ShowInNavigation">if set to <c>true</c> [show in navigation].</param> /// <param name="Title">The page title.</param> /// <param name="control">The web User Control to add to the page.</param> private void CreatePage(PageManager pageManager, Guid pageID, Guid parentPageID, string UrlName, bool ShowInNavigation, string Title, PageControl control) { // get backend node var parentPage = pageManager.GetPageNode(parentPageID); // Create a node in the SiteMap for that page. var node = pageManager.CreatePageNode(pageID); pageManager.ChangeParent(node, parentPage); parentPage.Nodes.Add(node); // set page properties node.RenderAsLink = true; node.Title = Title; node.ShowInNavigation = ShowInNavigation; node.UrlName = UrlName; // Create a PageData object to hold the actual page contents var pageData = pageManager.CreatePageData(); pageData.Template = pageManager.GetTemplate(SiteInitializer.DefaultBackendTemplateId); pageData.HtmlTitle = Title; pageData.Title = Title; pageData.Status = ContentLifecycleStatus.Live; pageData.Visible = true; pageData.Version = 1; //associate the node with the PageData object node.Page = pageData; // add admin control to the page if (control != null) pageData.Controls.Add(control); }
Install Widget
This code will install a widget into the “Page Controls” toolbox.
// get section from toolbox var config = initializer.Context.GetConfig<ToolboxesConfig>(); var pageControls = config.Toolboxes["PageControls"]; var section = pageControls .Sections .Where<ToolboxSection>(e => e.Name == ToolboxesConfig.ContentToolboxSectionName) .FirstOrDefault(); // add widget to section if it doesn't exist if (!section.Tools.Any<ToolboxItem>(e => e.Name == TestimonialsView.ViewName)) { var tool = new ToolboxItem(section.Tools) { Name = TestimonialsView.ViewName, Title = "Testimonials View", Description = "Public control for the Testimonials module", ControlType = "~/Modules/Testimonials/TestimonialsView.ascx", CssClass = "sfTestimonialsWidget" }; section.Tools.Add(tool); }
Errors
While developing your module, you may encounter the error “Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information”.
This problem can occur if you are modifying existing classes in your project as they may be cached in Sitefinity.
Rebuilding and restarting your website, as well as deleting your browser cache should resolve this issue
Creating an Installer Page and Uninstaller
A previous video exploring a basic intra-site module is available that explains how you can create an “Installer Page” as well as an uninstaller that will automatically delete all pages and unregister the module from Sitefinity.
This article is available here: Creating Intra-Site Modules in Sitefinity 4
Using OpenAccess
There were a few requests to see the example using OpenAccess. To see how easily you can convert this project to use OpenAccess instead of Entity Framework, take a look at this article: Building Data Layers Quickly with OpenAccess.
Download Project
A zip file containing the example code is below. This is just the module code and should be extracted into an existing Sitefinity website. If you don’t have one, be sure to register for a free trial.