This project is read-only.

Get other Content Item from Widget

Topics: Writing modules
Aug 26, 2012 at 1:16 PM
Edited Aug 26, 2012 at 1:16 PM

I have a page that displays Custom Widget and Content Type (with Autoroute Part and Custom Part).

to get the autoroute part from custom part i can do like so:


var autoroutePart = part.ContentItem.As<Orchard.Autoroute.Models.AutoroutePart>();

but how i can get the autoroute part from Custom Widget?

Aug 27, 2012 at 6:40 AM

A widget is a completely independent content item. It has no way of getting to your content item, it doesn't know it's there.

Maybe you're taking the problem from the wrong end, and should instead send parts of your content item to top-level zones using placement.

Aug 27, 2012 at 9:12 AM
Edited Aug 27, 2012 at 11:00 AM

I would get the URL by which cms get current page, but not from the browser and from the database. Because the page can be found by different URL (~/my-page-url or ~/My-Page-Url or ~/my-page-url?a=b etc.), but the database stores only one value.

I would like to use this URL for social networks plugins in my custom widget (such facebook like button).

Since difficult to get the Main Autoroute Part (by which cms get current page) I think the lower register url and trim query string.

Aug 28, 2012 at 10:35 PM

From your custom widget driver, you should be able to use IAliasService to get the RouteValues for the current request path. The returned route values contains an Id of the content item. You could use that Id to load the associated content item.

Sep 5, 2012 at 9:26 PM

Thanks, sfmskywalker.