【问题标题】:Theme Selector idea for a Blog Engine written with ASP.NET MVC用 ASP.NET MVC 编写的博客引擎的主题选择器想法
【发布时间】:2011-12-15 15:23:34
【问题描述】:

我已经开始构建一个完全不专业的博客引擎,并且不打算被任何人使用。所以,用简单的英语,我不能告诉你继续自己运行这个,你会很高兴。

您可能会看到我到目前为止编写的完整代码:

https://github.com/tugberkugurlu/MvcBloggy

虽然现在我正在研究 DAL,但我也在尝试制定我需要做的事情。我被困在这里的一点是如何处理博客引擎的主题选择。

  • 我应该如何开始构建基础知识?我应该创建一个骨架 html 并让其他人编写 CSS 并基本上选择它吗?还是别的什么?
  • 就 ASP.NET MVC 结构而言,处理此功能的最佳方法是什么。

到目前为止,我不确定你们中是否有人做过这样的事情。如果您能提供一种方法,我将不胜感激。

【问题讨论】:

    标签: asp.net asp.net-mvc asp.net-mvc-3 blog-engine asp.net-mvc-4


    【解决方案1】:

    完全主题化的 Web 应用程序是一个非常复杂的问题。在您拥有功能强大的博客引擎之前,您甚至不应该尝试解决它。​​

    一个简单且相当容易实现自定义的方法是允许用户选择 .css 文件,并确保页面中的所有元素都可以通过适当的 ID/类轻松寻址/选择。

    【讨论】:

      【解决方案2】:

      建议你看看NBlog temable blog engine

      https://github.com/ChrisFulstow/NBlog

      特别是查看类 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);
          }
      }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-10-04
        • 1970-01-01
        • 1970-01-01
        • 2011-12-29
        • 2010-11-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多