This project is read-only.

Widget to wrap a controller action

Topics: Administration, General, Writing modules
Sep 9, 2014 at 2:40 PM
My predecessor has made some stuff that's not really "the Orchard way". What he has done is basically:
-Created am IRouteProvider implementation and defined some routes
-Created controller actions and views to match the routes
-Setup a theme to match the routes urls
No because of this, I can't place widgets before the content rendered by the controller (because it's not a widget I can't edit the position).
What's the easiest way to be able to add a widget before the controller action is rendered? I was thinking about wrapping the controllers actions in a widget or something, or is there an alternative?
Sep 10, 2014 at 12:50 PM
Instead of returning views from the controller try the following:
public ActionResult Index (id) {
    // do stuff
    var yourContentItem = _contentManager.Get(id);

    return new ShapeResult(this, _contentManager.BuildDisplay(yourContentItem);
Sep 10, 2014 at 1:38 PM
Thanks for your reply. When I try that, the problem is that the controller actually build a viewmodel class, and the ShapeResult needs a dynamic shape
Sep 15, 2014 at 3:09 AM
One thing you could do is update the view of your controller's action by rendering zones before and after the content where you want to render shapes (including shapes created by widgets).

Another thing you could do is re-implement that controller as a widget. That's probably what I would do.