Theme Selector idea for a Blog Engine written with ASP.NET MVC

久未见 提交于 2019-12-07 08:36:26
Marco Staffoli

I suggest you to look at NBlog temable blog engine

https://github.com/ChrisFulstow/NBlog

In particular, look at the class ThemeableRazorViewEngine.cs

https://github.com/ChrisFulstow/NBlog/blob/master/NBlog.Web/Application/Infrastructure/ThemeableRazorViewEngine.cs

using System.Web.Mvc;
using NBlog.Web.Application.Service;

namespace NBlog.Web.Application.Infrastructure
{
public class ThemeableRazorViewEngine : RazorViewEngine
{
    private readonly IThemeService _themeService;

    public ThemeableRazorViewEngine(IThemeService themeService)
    {
        _themeService = themeService;

        base.ViewLocationFormats = new[]
        {
            _themeService.Current.BasePath + "/Views/{1}/{0}.cshtml",
            _themeService.Current.BasePath + "/Views/Shared/{0}.cshtml",
            "~/Themes/Default/Views/{1}/{0}.cshtml"                
        };

        base.PartialViewLocationFormats = new string[] {
            _themeService.Current.BasePath + "/Views/{1}/{0}.cshtml",
            _themeService.Current.BasePath + "/Views/Shared/{0}.cshtml",
            "~/Themes/Default/Views/Shared/{0}.cshtml"
        };
    }

    public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
    {           
        // bypass the view cache, the view will change depending on the current theme
        const bool useViewCache = false;

        return base.FindView(controllerContext, viewName, masterName, useViewCache);
    }
}
}

Fully theming web application is a very complex problem. You should not even attempt solving it, before you have a functional blog engine.

A simple and reasonably easy to achieve customization, is allowing the user to pick the .css file, and making sure all elements within the page are easily addressable/selectable with the appropriate IDs/classes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!