How can we pass data from orchard-module's view-model to orchard theme? #13465
Replies: 6 comments 9 replies
-
A theme is an extension that manages the look and feel of an Orchard Core site, by providing Razor or Liquid templates, CSS, JS files, and everything else. Modules can do the exact same thing as well (though themes are special that they override templates coming from any module). So, how you pass data from a "module's view model to a theme" is by simply following standard ASP.NET Core MVC practices (this is not unique to Orchard), and in your module, build your controller action, pass a viewmodel from it to a view, and as a baseline, you can have the corresponding view in the module too. Then, if you want to override from a theme how this view is displayed (because e.g. you run multiple sites either independently, or as multiple tenants, from the same source code), you can put a conventionally named template file into the themes Views folder, and it'll take effect. It'll behave exactly like if it were in the module, so you'll be able to access the viewmodel from it. See the docs for more info: https://docs.orchardcore.net/en/latest/docs/reference/modules/Templates/#overriding-views If you're new to theming in general, check out these resources too:
|
Beta Was this translation helpful? Give feedback.
-
In addition to what Zoltan said before you can make use of DI, by injecting your services from one module and get them from another module, again nothing special to OC here FYI you can have a look to OC code base of how the modules interact with each other |
Beta Was this translation helpful? Give feedback.
-
If I understand your question correctly, you are creating some ViewModel in your MVC controller that you need to use within your Layout. The best choice is to use zones in your Layout and add your ViewModel using |
Beta Was this translation helpful? Give feedback.
-
The reason why I'm using Welcome-Page is to have orchard-users to contribute data through the Admin-Dashboard and I can capture it using How do I go about bringing EssentialData property into CustomLayout? |
Beta Was this translation helpful? Give feedback.
-
MyTestPartDisplayDriver:MyTestPart.cshtmlContent-WelcomePage.cshtml:Layout-Content-WelcomePage.cshtmlOutputCalling the shape directly from the Layout-Content-WelcomePage:Internal server error due to directly displaying shape in Layout-Content-WelcomePageI tried displaying shape from layout after modifying the displaydriver with the "layout" location. Still I'm facing 2 issues, if I use But in none of these scenarios, I'm able to access the ViewModel of MyTestPart in the |
Beta Was this translation helpful? Give feedback.
-
In display driver, you defined three locations. First Here when Solution is to keep only |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I need to pass data from orchard-module's view-model to orchard theme. There are multiple themes and view-model.
In my example, I have multiple applications for which landing pages will be served from orchard and the remaining pages are part of the application, so I need to create a controller which can pass data and create interactivity between this.
What are the ways I can accomplish this?
Beta Was this translation helpful? Give feedback.
All reactions