This project is read-only.

How to get the current routable content part from a widget?

Feb 14, 2011 at 5:28 PM
Edited Feb 14, 2011 at 5:29 PM


Team, is there a possibility to retrieve the currently displayed, routable content item (eg. Page) from another, different content item (eg. Widget) rendered on the same page? I don't want to use current request URL and query the store for a corresponding item as it looks like a dirty workaround... Or maybe I could somehow access the list of all content items rendered in current request? This would be even better:)

Cheers, Piotr

Feb 14, 2011 at 7:50 PM

Can't you access the shapes in the Layout from WorkContext and get the shapes which should contain the data your looking for from the different zones. This requires though that the code for those areas be run before yours so that it exists at the time you look for it, so maybe this isn't a good idea, but maybe worth digging a bit in this direction.

Feb 14, 2011 at 7:53 PM

You could do that but I think you would be doing it backwards: it should be the content item that pushes stuff rather than a widget that tries to pull. You can see an example of pushing shapes to a zone in the Vandelay Theme Picker module:

You could add a part to the content type that has a zone and position setting and then have the driver push a shape accordingly. Seems a lot cleaner to me.

Feb 14, 2011 at 11:05 PM

Hi! Thanks for reponses - I'll try both solutions. Bertrand, I agree - your solution is much cleaner, but I have no control over the currently displayed item. I just want to grab the currently displayed routable item and fetch some data from it (on which the widget depends) - that's all. Ok, I can create the part that would pull the data from an item and pass it somewhere, but then I'd need to attach it to currently existing routable items (and to all defined in future). That is doable though, but seems like an overkill for retrieving just two or three strings...


Feb 15, 2011 at 12:01 AM

OK then, write a handler, or a shape table provider and handle some events then.

Feb 16, 2011 at 8:21 AM

"It should be the content item that pushes stuff rather than a widget that tries to pull."

I do understand that design philosophy as well, but I think it also makes sense to go the other way in some cases...

For example, the map widget example that is in the "Writing a Widget" article at

The widget in the example requires manual configuration (of values like latitude and longitude) for every use.  So if I had 10 content pages that each described a location, and I wanted a map in the sidebar on each of these pages, I'd need to configure the map widget 10 times, and I believe that means defining 10 layers.

Instead, I believe it would make a lot of sense for the page to include the map part, and for the widget to go look in the current page's content for that part.  This allows managing the coordinates of the location together with the page content, and the configuration of the map in just one layer -- and unlike the "push" model, the zone to display the widget in can be configured and changed in just one place.  The widget and content part don't necessarily have to know about each other and can even be written by different people.  If someone else wanted to create another widget that uses the coordinate data on this page in a different way, it can be created too.  And the administrator can add it to any part of all of these pages easily.

Feb 16, 2011 at 8:52 AM

"Can't you access the shapes in the Layout from WorkContext"

I tried this, but I wasn't able to find the actual models that represented content items or their parts, so I'm not sure how to get to these from the cshtml running as the widget.
If you were able to do this, can you show me how?

Feb 16, 2011 at 2:57 PM

pszmyd has written an excellent blog post on how to do this.  Thank you, @pszmyd!

Feb 16, 2011 at 3:38 PM

You're welcome:)

I totally agree that some kind of mechanism that would allow sharing data between items is sometimes necessary. On the other hand, I don't argue with the fact that data isolation in content parts and items is the crucial thing to keep things clean. Unfortunately, this approach also forces data duplication in many cases:(

An idea came to my mind to build a module that would allow to create data links (one-way or two-way) between different items/parts/item fields. You'd think of those links as of a user-defined relations between specific items. Of course a nice admin GUI would be necessary. It would bring a huge boost in terms of flexibility, i think.


Feb 16, 2011 at 7:53 PM

Guys, I just had an idea. Hopefully I'll have a little module today or tomorrow.

Feb 19, 2011 at 10:03 PM

Could you tell us briefly about the mysterious module idea?;) 

Feb 22, 2011 at 1:36 AM

It's allowing most shapes to be moved to other zones, global or local. It does involve some ninja tricks that made the whole thing take more time than I thought. I'm not even sure it can work yet. But if it does it will be pretty cool and powerful.