So I keep running into the same problem – I am building a small website for somebody and I need to provide them with a way to update the content of their site so I don’t have to. Basically, I need a lightweight and flexible content management system that is easy to use.
If The Shoe Fits…
When I first thought of a lightweight CMS, I thought of graffiti. It sounds like exactly what I need. So I downloaded the express edition and started evaluating it. It seemed like a nice product and all is not free for commercial use ($399 is the cheapest commercial licence) and I can’t afford that price tag when building small websites.
Enter BlogEngine.net. My favorite blogging platform. There, I said it. Well, I use it to run my blog and I am constantly tinkering around with the site all of the time because I enjoy using BlogEngine.net so much.
I thought that BlogEngine.net has all of the key pieces I needed for my lightweight CMS:
- A WYSIWYG Editor
- A Metaweblog interface
- Tons of extensibility
Basic Idea
I decided to base my CMS implementation on the concept of pages. Most blog engines have two distinct types of content: pages and posts. Posts are the typical type of content that becomes part of your blogs feed whereas pages are usually static content which can be anything outside of a blog post (for example an ‘About Me’ page). BlogEngine.net already has everything I need to get the content of page created and persisted in a data store (it supports xml and sql server out of the box). I decided to write a web control which I can place on any webpage and include the contents of a given page from the data store.
I made a control called PageViewer which you can place on the page like this:
This control basically just looks up the page using the given id (this functionality is all provided by the existing BlogEngine.Core library) and displays its content. Here is the rendering logic
if (PageId != Guid.Empty)
page = BlogEngine.Core.Page.GetPage(PageId);if (page != null){ ServingEventArgs arg = new ServingEventArgs(page.Content,ServingLocation.SinglePage);BlogEngine.Core.Page.OnServing(page, arg); if (arg.Cancel) Page.Response.Redirect("error404/", true);
if (DisplayTitle) { writer.Write("<h1>"); writer.Write(page.Title); writer.Write("</h1>"); }
writer.Write("<div>"); writer.Write(arg.Body); writer.Write("</div>");}
This code is pretty straight forward – all it does is get an instance of the page and then display its title in <h1> a tag and its body in <div> tag. This logic is actually straight from the existing page retrieval code that already exists in BlogEngine.net. This web control is pretty much the only new code I had to write. The rest of the project mostly involves moving files around and removing parts of the BlogEngine.net framework that I don’t need.
Armed with this control, we are ready to start converting the static pages from the old version of the website to be BlogEngine.net pages which can be stored and retrieved using the BlogEngine.Core classes.
Themes
It’s also worth noting that there are many themes available for BlogEngine