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 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
Atanas Valchev is a Tech Support Engineer at Telerik. He joined the Sitefinity Support team in March 2012.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites
Progress collects the Personal Information set out in our Privacy Policy and the Supplemental Privacy notice for residents of California and other US States and uses it for the purposes stated in that policy.
You can also ask us not to share your Personal Information to third parties here: Do Not Sell or Share My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.