Orchard CMS中新页面的新布局

时间:2017-11-13 01:59:46

标签: orchardcms orchardcms-1.6 orchard-modules

有没有办法用新布局显示新页面? 现在我正在做的是创建一个新模块,但不使用[主题] 我正在寻找一种更简单的方法吗? 感谢

1 个答案:

答案 0 :(得分:0)

Assumed by layout you mean theme you can implement Orchard.Themes.IThemeSelector to select a specific theme. Here is an example which shows a theme selector which picks the theme based on a ThemePickerPart:

public class ThemePickerPartThemeSelector : Orchard.Themes.IThemeSelector
{
  public ThemePickerPartThemeSelector(Orchard.ContentManagement.IContentManager aContentManager)
  {
    mContentManager = aContentManager;
  }

  public Orchard.Themes.ThemeSelectorResult GetTheme(System.Web.Routing.RequestContext aContext)
  {
    // get current content item, based on http://www.ideliverable.com/blog/getting-the-current-content-item-in-orchard
    object lID;

    if (aContext.RouteData.Values.TryGetValue("id", out lID))
    {
      string lIDStr = lID as string;

      if (lIDStr != null)
      {
        int lContentID;

        if(int.TryParse(lIDStr as string, out lContentID))
        {
          // try to get theme from theme picker part
          var lContentItem = mContentManager.Get(lContentID, Orchard.ContentManagement.VersionOptions.Published);

          if (lContentItem != null)
          {
            var lThemePickerPart = lContentItem.As<ThemePickerPart>();

            if (lThemePickerPart != null)
            {
              if (!string.IsNullOrEmpty(lThemePickerPart.ThemeId))
              {
                // return selected theme
                var lResult = new Orchard.Themes.ThemeSelectorResult {Priority = -3, ThemeName = lThemePickerPart.ThemeId};

                return lResult;
              }
            }
          }
        }
      }
    }

    return null; // use configured theme
  }

  // private
    private Orchard.ContentManagement.IContentManager mContentManager;
}
相关问题