BlogEngine.NET Architecture and source Code Analysis series part11: Development extension (Next)

Source: Internet
Author: User
Tags requires blogengine root directory

Custom Theme

Personalized theme is a perfect blog system in the necessary, but also a bright spot. In this article I will show you the third development feature of BlogEngine.NET, which is the custom theme. The emphasis of this paper is on the development specification and realization principle of blogengine.net. If you are familiar with the architecture of BlogEngine.NET, then developing a own theme is a very simple matter, if you do not know, then you can follow the specifications described in this article to develop a custom theme.

The theme in the BlogEngine.NET

In BlogEngine.NET's source code, three theme are stored by default (standard default, mobile mobility, Indigo), and more theme you can download to its official site. Similarly, these theme support hot-swappable, we can install it by simply placing the downloaded theme in the themes directory. It is believed that this kind of theme will bring more use to the user's feeling. Because blogengine.net open source code, so for theme development also completely by the user control. If you want to know how powerful this theme is, look at the official site of BlogEngine.NET know, it is estimated that the use of blogengine.net, and then changed a theme do.

Specification and principle

For the user to use which theme is stored in the blogsetting, in the Settings page we can see a drop-down list to select the theme, the Drop-down list of data by reading the themes directory under the subfolder name obtained, This requires us to develop theme with the name of theme as the name of the folder. One problem to note is that all of the. aspx codebehind in the root directory of the BlogEngine.NET Web site are inherited from Blogbasepage, which is inherited from the page class, which means that blogbasepage will unify some of the actions of some pages. I will analyze this class in the next article.

There is a section of code in Blogbasepage:

private string _theme = BlogSettings.Instance.Theme;
<summary>
Assignes the selected theme to the pages.
</summary>
protected override void Onpreinit (EventArgs e)
{
if (request.querystring["theme"]!= null)
_theme = request.querystring["Theme"];
MasterPageFile = Utils.relativewebroot + "themes/" + _theme + "/site.master";
Base. Onpreinit (e);
//....
}

This code is when the page is initialized (note that it must be placed in this processor) to set the page's masterpagefiles to the Site.master in the directory of the subject name set in Blogsetting, which requires us to create the page's primary file site when we develop our own theme . master.

In addition, after the implementation of the Postviewbase and Commentviewbase (the two classes will be detailed in the next article), the display of post and comment is also found in the directory where the subject name is set in Blogsetting Postview.ascx (directly inheriting from Postviewbase) and Commentview.ascx (directly inherited from Commentviewbase), which requires us to create our own theme the display interface of the article to be created Postview.ascx and comment display interface Commentview . ascx.

The above several files are necessary to develop the blogengine.net theme, actually also formed a complete foreground page. Of course, you can also define your own layout, CSS, pictures and so on. How exactly should these files be defined, take standard as an example, let's take a look at its implementation first.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.