Categories
Bloggers
Blogs RSS feed

Create a Sitefinity Theme in a Class Library

by Atanas Valchev

This blog post will outline how to create a Sitefinity Theme in a class library.

To start, if you do not have a Theme, you can generated one with Sitefinity Thunder. After that, add a new class library and move the theme files to it: http://screencast.com/t/m6mlNPlOkMs.

In order to be able to resolve the assembly when registering the theme, we need to add an empty Reference.cs class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace CustomTheme
{
    public class Reference
    {
    }
}

 

After that, the theme can be registered just like a regular theme: http://screencast.com/t/9QxVLnI5pfx. The full namespace path is: CustomTheme.WebsiteTemplates.WebsiteTemplates1.App_Themes.WebsiteTemplate1. You will notice that for the assembly we enter the Reference class, otherwise we will not be able to resolve the assembly. Since we are using a separate assembly, the build action for all resources need to be changed to Embedded Resource.

The next step, is for all the stylesheets, JavaScript, etc. to be added as WebResources in the AssemblyInfor of the Class Library that we put the Theme in: http://screencast.com/t/2hMVo27Dp

After the solution is built, the theme, master pages and resources will be in this assembly. In order to use the master page, you will need to apply using the API. First, register a Virtual Path: http://screencast.com/t/93OT4fokT42n

After that, create a new one or get an existing template and apply it like this:

var pageTemplateId = Guid.Parse("a7ff55b2-41b2-63fe-9626-ff0000474a57");
 
          PageManager pageManager = PageManager.GetManager();
 
          PageTemplate template = pageManager.GetTemplate(pageTemplateId);
 
          var master = pageManager.TemplatesLifecycle.GetMaster(template);
 
          master.MasterPage = "~/CustomTheme/THE_PATH_TO_THE_MASTERPAGE";
 
          pageManager.TemplatesLifecycle.Publish(master);
 
          pageManager.SaveChanges();

 

 More information on the page templates API can be found here:Page Templates

 

Comment

  1. RadEditor - HTML WYSIWYG Editor. MS Word-like content editing experience thanks to a rich set of formatting tools, dropdowns, dialogs, system modules and built-in spell-check.
    RadEditor's components - toolbar, content area, modes and modules
       
    Toolbar's wrapper 
     
    Content area wrapper
    RadEditor's bottom area: Design, Html and Preview modes, Statistics module and resize handle.
    It contains RadEditor's Modes/views (HTML, Design and Preview), Statistics and Resizer
    Editor Mode buttonsStatistics moduleEditor resizer
      
    RadEditor's Modules - special tools used to provide extra information such as Tag Inspector, Real Time HTML Viewer, Tag Properties and other.