Sep 8, 2011 at 2:52 AM
Edited Sep 8, 2011 at 3:21 AM
I've got a few questions around the ContentManager. I know how to use this within a controller, by passing it into the constructor of a controller in a custom module. See below:
public HomeController(IContentManager contentManager)
_contentManager = contentManager;
public JsonResult Index()
List<WhatsAroundItem> items = new List<WhatsAroundItem>();
// Load the WhatsAround content items
IEnumerable<ContentItem> whatsAroundContentItems = _contentManager.Query().ForType("WhatsAround").List();
foreach (ContentItem contentItem in whatsAroundContentItems)
ContentItemRecord contentItemRecord = contentItem.Record;
if (contentItem == null)
WhatsAroundItem item = new WhatsAroundItem(contentItemRecord.Data);
// Allow JSON GET as this is insecure data
return base.Json(items, JsonRequestBehavior.AllowGet);
My question is how can use this elsewhere, i.e. use it within any code or even within a code block within a shape template?
Is there any code I can use to instantiate or get a reference to the IContentManager elsewhere?
If anyone can point me to some other good examples where the IContentManager is used that would be great.