Is it possible to use razor layouts with Orchard CMS and bypass the theming

拈花ヽ惹草 提交于 2020-01-29 15:31:30

问题


A little bit of context

We have a recent MVC4 web application used by a lot people that we would like to port to Orchard CMS. Even though this is an "admin" type of application, we don't want it to be part of the admin section of Orchard. This application is currently live and we would like the move to Orchard to be as invisible as possible to the end-user.

Where we are now

We followed this answer as how to Integrate existing ASP.NET MVC application with Orchard CMS but we use layouts (Razor not Orchard) and it is not working (by default) with the way Orchard renders pages (the views returned by the controllers actions are displayed without the layouts - _ViewStart.cshtml is ignored). I have tried to specify the path of the layout in the View method but it doesn't work or the path is not good since we are in a module. Is there a way to tell Orchard to use a _layout.cshtml file and bypass Orchard theming?


回答1:


It is possible to bypass Orchard themes. Note that I am doing this with MvcMailer, so the outputted e-mail is "templated" HTML with a Layout. I cannot definitively say this works on regular pages, but you can try it. Just slap this in your view:

@inherits System.Web.Mvc.WebViewPage<object>
@{
  Layout = "_Layout.cshtml";
}

Caveat: you cannot use the newer @model directiv. I just fall back to the old style and put my model where "object" is:

@using Namesapce.ViewModels
@inherits System.Web.Mvc.WebViewPage<MyViewModel>

Otherwise, it's pretty straightforward to create a Theme and override any of Orchard's shapes. There are two ways I do it:

  1. Create a straightforward theme, override shapes (say you want a different Login, just create Login.cshtml in the Theme's ~/View folder), use alternates (use Layout-homepage.cshtml to override the layout for the homepage), have your .css, etc.;
  2. Use a couple of tricks to override the theme with code from a module, and create your own views and shapes in a theme folder. You can, for example, have a Layout.cshtml file in your theme with code that displays a shape. However, the shape itself (.cshtml file) lives in your module, which is great for using a dashboard type theme that will call a shape that is named the same in your different modules but shows different content. The code for this is a bit more in-depth. Just ask if you need samples.



回答2:


tl;dr No, it is not possible.

I don't like answering my own questions but since Bertrand Le Roy commented my question instead of answering it (no hard feelings) and he is part (or was?) of the Orchard team, I will answer with what I know, until someone comes with a better answer.

From what I understand, to be part of an Orchard project is to embrace it all the way, there is no in between. The custom (Orchard) view engine (which works with zones, layouts, widgets, shapes, etc.) cannot be bypassed (fallback to default MVC engine) in a module. As Bertrand suggested, I should convert my project to Orchard theming.



来源:https://stackoverflow.com/questions/15347551/is-it-possible-to-use-razor-layouts-with-orchard-cms-and-bypass-the-theming

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