Get ContentItem from ContentItemRecord

Topics: Customizing Orchard, Troubleshooting, Writing modules
Aug 22, 2012 at 8:03 PM

I have a ContentPart that has a property on it that gives me the related ContentPartRecord of a different content item.  Is there anyway to get to the related content item from its content item record, baring in mind that I am in ContentPart?

The background to this is that I am in a view listing the child content items, I need to access the parent content item to display its title.  The view is a generic view (shopping cart) so I have no control over the driver. I am just creating an alternative view.

The child content items are not containable part.

Any ideas?

Cheers,

Jeff

Aug 23, 2012 at 10:46 AM

Ok I ended up doing this in the view...

var contentManager = Html.GetWorkContext().Resolve<IContentManager>();

Once I got hold of the ContentManager I was able to retrieve the ContentItem :)

Developer
Aug 23, 2012 at 12:17 PM

You could have a LazyField on the part, initialized from a Handler, that would fetch the item through ContentManager. Look at how CommonPart does this with Container.

Coordinator
Aug 27, 2012 at 7:37 AM

Don't do that in the view. This should be done in the driver, where you can inject dependencies the regular way.

Aug 27, 2012 at 11:40 AM

@piedone.... this sounds like a neat solution, I will give that a go, thanks.

@bertrandleroy.... I would normally do this in the driver, however this is for an alternative view of a 3rd party module, so I don't want to change the code in the module, or add a dependency to my module.  I think Piedone's solution is the way forward.

Coordinator
Aug 28, 2012 at 4:48 AM

I see. Unfortunate.