Displaying external data without Parts but with Zones

Topics: Writing modules
Aug 12, 2011 at 10:33 AM

I'm drawing in content from an external datasource that doesn't touch Orchard. It renders using the standard MVC structure of cshtml views and RenderPartial() functions.

public ActionResult LocationDetails(int id)
  LocationDetails details = _externalService.GetLocationDetails(id);
  return View(details);

In a location in one of my partial cshtml files I would like a different Module to be able to inject HTML. Is this possible without converting my entire object to nested Shapes?

Aug 12, 2011 at 2:39 PM

You can define a global Zone from any View, just by using it. So in you partial view you display some zoned elements by calling:


And from your module you add stuff to this zone. From a view for instance it would be:

Layout.YOURZONE.Add("Foo", 5);

You can also access the Layout from code, through WorkContext.Layout

Aug 16, 2011 at 9:42 AM

Thanks for the tip! I ended up spying on the MenuFilter: I created a Filter in my module that added my additions to YOURZONE via  WorkContext.Layout.YOURZONE.Add("Foo", 5). 

Downside: difficult for other parties to implement (they would have to create filters instead of being able to attach parts), and it gets called for each and every request (which is what you want for the navigation, but not for my module).


I'm now trying out a new approach: converting my LocationDetails object to a shape, and rendering that using the orchard rendering engine.

var contentItem = _contentManager.New(ContentPartNamingConventions.ApplyTo<LocationDetailsPart>());
var ldr = contentItem.As<LocationDetailsPart>().Details = details;
return new ShapeResult(this, _contentManager.BuildDisplay(contentItem));

Hopefully I'll be able to dynamically create a contentitem that doesn't exist in the database, and render it using Orchard. Haven't got it working yet, though, but I'll keep you updated.