Override Widget Template

Topics: Customizing Orchard, Writing themes
Feb 25, 2011 at 3:55 AM

Is it possible to override a widget layout template? I've tried created a view called widgetname.cshtml and widgets_widgetname.cshtml, but neither seem to override.

Coordinator
Feb 25, 2011 at 4:45 AM

Try Content-widgetname.cshtml?

Feb 25, 2011 at 5:10 AM

Thanks for responding Bertrand. I've tried that as well and it doesn't seem to work. In fact, I tried creating a blank Content-widgetname.cshtml (ie: Content-TwitterWidget.cshtml) and it doesn't seem to work.

The reason I'm asking is that I'm creating a custom widget that I'd like to share with everyone but change the layout for my own app. This way if I update the widget, the view shouldn't have to change unless the property names change.

Coordinator
Feb 25, 2011 at 5:14 AM

Did you try to override the template of the part instead?

Feb 25, 2011 at 5:35 AM

Do you mean expand out the widget and place the template override in there?

Coordinator
Feb 25, 2011 at 5:37 AM

I'm not sure I'm following you now. what I'm saying is that your widget is a content type, made of parts. Usually, a widget actually is just one specialized part. That one should be easy to override by finding out what shape its driver emits.

Feb 25, 2011 at 5:48 AM

Its not you, it's me. :) I'm pushing the limits after a late night of COD last night.

My specialized part is called Weather. So how would I override that?

Coordinator
Feb 25, 2011 at 5:52 AM

Well, what's the name of the shape that the driver emits for that part?

Feb 25, 2011 at 6:03 AM

It's ContentShape. So, the name should be Content-Weather.cshtml?

Coordinator
Feb 25, 2011 at 6:05 AM

The name of the shape is ContentShape? That doesn't sound right. Is that a module from the gallery or something you're building?

Feb 25, 2011 at 6:09 AM

Both. To eliminate my code in case its something I did wrong, lets use the LatestTwitter module for instance.

Coordinator
Feb 25, 2011 at 6:13 AM

OK, well, the name of the shape they are emitting is Parts_TwitterWidget. So you should be able to override that with Parts/TwitterWidget.cshtml.

Feb 25, 2011 at 6:16 AM

Thanks for straightening me out. That works for both widgets. Can't wait to hit you up with other items next week at the Summit.